send war to another job in jenkins - 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!

Related

How to add a script file in Jenkins job workspace remotely and run it as part of build step

Is it possible to add a file to Jenkins Job workspace and run it from build step.
The Jenkins is on a remote folder and I cannot directly access workspace as a folder structure.
Is there any way to achieve this from Jenkins dashboard?
Yes you can do that. In order to achieve that you can place your file in Git repository and then in the Jenkins job you can pull it and then you can execute it as a part of Jenkins job

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.

Jenkins: how to run builds in unique directories

I am configuring Jenkins for the first time, have been a user of it until now.
I read the documentation and understand what "$WORKSPACE" means on the slave.
I had a misconception that by default the jobs on Jenkins Slave run in a unique directory per job inside the workspace directory. This doesnt seem to be the case.
How do I assign a unique directory per job run?
Will Jenkins automatically cleanup this job run directory after its done?
By default jenkins runs from $WORKSPACE/JOB Name ; here WORKSPACE is defined in the node configuration. This could be changed by choosing Advance Project options -> Use custom workspace under your job configuration.
Regarding cleanup: Choose Build Environment -> Delete workspace before build starts under jobs configuration if you like to cleanup for each new job.
Jenkins will create workspace directory by default if jobs is successfully executed at-least once

How to copy the artifacts from slave to Jenkins workspace?

I'm running a jenkins job on a slave and i want to store the generated artifacts in the server.Since the job is currently running on the slave the artifacts are also created there.
I tried using post build actions --->archive the artifacts.But it throws the following build error
ERROR: No artifacts found that match the file pattern "**/*.gz". Configuration error?
ERROR: '**/*.gz' doesn't match anything: '**' exists but not '**/*.gz'
Any help in this regards is highly appreciated.
Sounds like Copy To Slave Plugin is what you need
It can copy to slave (before build) and from slave (after build)
Copy files back to master node:
To activate this plugin for a given job, simply check the Copy files back to the job's workspace on the master node checkbox in the Post-build Actions section of the job. You then get the same two fields as for the Copy files to slave node before building section (note that label in the screenshot is old):
if you want to copy artifacts from JobA to the workspace of some other Job, you can do it using the Copy Artifact Plugin which is very simple to understand.
In case you just want to archive the artifacts already in JobA, then you are already in this direction and need to check what you are missing... are you sure that the artifacts are in the current workspace?
Doron

Resources