Deploy war generated on another job - jenkins

I'm coding some integrations tests, and to run then I would like to first have jenkins running unit tests and quality scan in my code. On this first job the war would be generated.
After generating the war and sending statistics to SonarQube server I want to deploy the artifact generated on the first job to the test environment. I don't want to do this in the first job, because it is possible that the deploy process fails because of the test environment and if that happens the sonar statistics wouldn't be stored.
So I want to deploy the artifact generated in the first job to my tomcat on the test environment and trigger a third job to run the integration tests using the deployed war.
How can I configure jenkins to deploy an artifact generated during a previous job execution?
*I tried shared workspace, but couldn't figure out how to do it, and after a while I discovered it is a bad practice (because of files locked)

Well, I managed to do it using the Copy Artifact Plugin, it allows a job to copy the artifact generated by other job

Related

Deploying Jenkins Artifact Built by Another Job

I installed the Deploy Plugin on my Jenkins in order to automate the deployment of my Maven built war packages to Tomcat 7. The problem is that I am able to use the plugin to deploy to a remote Tomcat server only if they are made within the same job that uses the deploy plugin. In other words, I have not been able to set up a standalone job that deploys artifacts made by a different job.
For example, I have a job named pack.foo. It uses the source code in /var/lib/project/module to create module.war and put it in /var/lib/project/module/target. However, because of the Maven version setup, the artifact posted on pack.foo's artifact page is something like module-2.0.0-SNAPSHOT.war.
The only way I am able to deploy module.war is if I add a Post-build Action to pack.foo and specify **/module.war to be a remote Tomcat manager URL (provided I have the manager's credentials in Jenkins config). Then the job's console output logs that /var/lib/project/module/target/module.war was deployed to that URL:
Deploying /var/lib/project/module/target/module.war to container Tomcat 7.x Remote with context
[/var/lib/project/module/target/module.war] is not deployed. Doing a fresh deployment.
Deploying [/var/lib/project/module/target/module.war]
How can I use this, or another plugin, to deploy a WAR artifact that was made in a separate Jenkins job? I would like to have separate jobs for artifact creation and deployment. The plugin wasn't finding **/module-2.0.0-SNAPSHOT.war or even **/module.war built by another job even though there was definitely a file on disk that matched that pattern.
See the paragraph on the Deploy Plugin's page you linked:
How to rollback or redeploy a previous build
There may be several ways to accomplish this, but here is one suggested method:
Install the Copy Artifact Plugin
Create a new job that you will trigger manually only when needed
Configure this job with a build parameter of type "Build selector for Copy Artifact", and a copy artifact build step using "Specified by build parameter" to select the build.
Add a post-build action to deploy the artifact that was copied from the other job
Now when you trigger this job you can enter the build number (or use any other available selector) to select which build to redeploy. Thanks to Helge Taubert for this idea.

How to totally avoid creating Jenkins Artifacts after each build?

I am running my wedriverio(selenium wrapper in javascript) tests on Jenkins
After each build the jenkins creates and attaches artifacts which is taking very long time (the test cases complete in 2 minutes, but the artifact steps take about 1 hr).
I also noticed that artifact is allure-report.zip
Is there any significance of this artifact if I already have console logs and allure-reports generated?
How to not generate and attach artifact after each build?
Jenkins has no control over the artifacts being created after starting a build via the execute shell command. The build itself is what creates artifacts. Parts of the build process that can also create artifacts are post-build actions such running tests or plugins.
I suggest you familiarize yourself with your Jenkins job to locate what creates the allure_report.zip file.
With Jenkins you can control which artifacts you want to preserve and make available easily on the UI via the Archive the artifacts in Post-build Actions. This does not create the artifacts. It simply tags and archives them as something special to be available outside of the workspace. If this is the step you think is slow (attaching the generated allure_report.zip file), you can remove it from the list of files to archive.

Run script before removing job in Jenkins Pipelines

I'm setting up a development environment where I have Jenkins as CI server (using pipelines), and the last build step in Jenkinsfile is a deployment to staging. The idea is to have a staging environment for each branch that is pushed.
Whenever someone deletes a branch (sometimes after merging), Jenkins automatically removes its respective job.
I wonder if there is a way to run a custom script before the automatic job removal, then I would be able to connect to the staging server and stop or remove all services that are running for the job that is going to be deleted.
The plugin multibranch-action-triggers-plugin might be worth a look.
This plugin enables building/triggering other jobs when a Pipeline job is created or deleted, or when a Run (also known as Build) is deleted by a Multi Branch Pipeline Job.

send war to another job in jenkins

I've built two jobs in my jenkins instance:
Gradle job builds war task and generates a war file ready to be deployed.
Docker job builds a Docker image from a repository.
Both are working fine. However, the second one depends on the first one. So, Docker job needs to use the last war file generated by Gradle job.
How could I be able to do that?
You can use parameterized job trigger plugin to trigger sub jobs with parameter. You have to do the following to resolve above problem:
Create parent job which will have two sub jobs which you mentioned.
Then trigger first job and archive the artifacts which is war file.
Then pass last trigger build number of first job to second job and start that job. Use Copy artifacts plugin to copy war from first job with specific build number which was passed before starting.
This will resolve your problem!!!
Use a post build task for your first job (Gradle job), just cp the war file into the workspace of Docker job. Then configure Docker job so that it does NOT clean workspace before build. And for the post build action, choose delete workspace after build. This will ensure you will only have the latest war file in Gradle job workspace. Also, you should use post build trigger, if your not using that already.
Good Luck!

Jenkins - How to get test results?

I'm trying to create the following scenario:
One instance running Jenkins server. It polls repo and if change occurs it spins up a production instance of my app - let's code name this instance APP_INSTANCE. NOTE: this APP_INSTANCE is NOT a Jenkins slave in any way. It is literally the production server of a web application. No Jenkins stuff installed.
Jenkins passes some configs to APP_INSTANCE like BRANCH_NAME.
APP_INSTANCE checks out BRANCH_NAME and runs test suites.
Jenkins polls APP_INSTANCE via ssh to see when test report file is done being generated.
If Jenkins finds test report file, it assumes tests are done and it copies test report file.
This last part is the part I'm stuck on, how to make Jenkins:
1. copy a file from APP_INSTANCE
2. parse it for test results so it can display them in its web interface. (I assume the test report format has to be jUnit or some sht, right?)
So am I dumb for trying to build this?
P.S. I'm using AWS and this is all happening in the cloud.
Try this plugin.
https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs
And read this:
Setup Jenkins to monitor external job

Resources