User prompt for downstream job - jenkins

I would have job1 with one dropdown parameter - ENV (DEV, QA, etc) which run and download some files from git repo, and after this it should run job2 which has several another parameters that would be filled via Extended Choise Plugin from downloaded files during job1.
And this job2 should wait for user to check/edit default values of these parameters.
And after setting all parameters user can press Build button to start building.
I don't need to auto-run job2 because I need user to see all the parameters from job1.
Is it possible in Jenkins?

You can create a pipeline and in the steps you can ask user for user input to accept or decline for the second job. This way, you can also be notified via an email when the first job completes.
Just refer to the input in the pipeline syntax options.

Related

How to use parameter to controller job post build action in Jenkins

I am creating a free style jenkins job and use some post build actions such as: deploy to dropbox, deploy to s3 etc. I want to build two boolean parameters for this job to control whether deploy build results to drop box or s3. For example, if user trigger this job but he doesn't select the s3 parameter, I don't want to trigger the s3 post action. How can I achieve this in Jenkins? I didn't find there is any configurations for that.
You can achieve your requirement using Flexible Publish Plugin.
You need to install the above plugin in your Jenkins.
Then create a freestyle job that will control your choices, that is whether you want to build only Deploy to S3 in the post build or only want to build Deploy to Dropbox in the post build or you want to trigger both the build at once.
In this job create two choice parameters, DEPLOY_TO_S3 and DEPLOY_TO_DROPBOX both with choices YES and NO.
4.Then in the Post-build Actions section choose the Flexible Publish Plugin and do the following configurations and save the job.
Now build your job with parameters and select YES to trigger the down-steam jobs and No to not to trigger the down-stream jobs.
And you are done :)

How to send first pipe result to second one in Jenkins pipeline?

we use Jenkins as CI tools.
we want to separate login from other process.
we define a job for login, in this job we validate user and if user is valid we get user id.
at other job we need to have user id to generate result,Our problem is how we can send first job result(here:user id) to second one?
You can do this with the use of two plugins:
EnvInject Plugin
Parameterize Trigger Plugin
EnvInject allows you to inject variables into the Jenkins environment so they are available even after that build step.
Parameterize Trigger plugin allows you to pass information in this build job to another build job you want to start as parameters.
Once you've determined the username (I assume in some sort of batch or bash, you don't note the OS) you'll need to write it to a file on the system using a key=value pair. Then use EnvInject to get the value from the file into the jenkins environment. After that you'll use the parameterize trigger plugin to build the next job with parameters. This will require that you check the This build is parameterized box in the second job and that you define the appropriate parameters (perhaps with a default value that you can use to intentionally fail the build if you don't get a good value).

Executing Jenkins email-ext plugin not as last post-build action

I am using the email-ext plugin v.2.38.1 (post-build action "Editable Email Notification") on Jenkins v.1.566 to send e-mails after the build when certain conditions are met.
When using multiple post-build actions, I got the impression that the email-ext plugin always comes last and is executed after all other actions, no matter how I put the order of actions in the configuration. Other plugins respect the order and are executed accordingly as described in this issue.
Is there any possibility to execute another post-build action after sending the e-mails? In my case, I would like to run a shell script doing some clean-up in the workspace which cannot run before because it will delete a file that is part of the e-mail body.
One could work around this by defining an extra clean-up job which is triggered after the main job is completed, however, I would prefer having everything defined in one job only.
The emailing is a publishing action which occures always after build and post build actions ..
Additionally I think you should clean something before running the job (at startup eventually) but never at the end.
How can you study your issues if you destroy all materials that should enable you to do so ?
The step Editable Email Notification is always executed at last in the post-build actions, but you can use a Editable Email Notification Templates step which can be executed in the order you specified in post-build actions

How to run parametrized build after commit to repository?

I have parametrized build job in Jenkins. It has configured SCM polling and the build job is started after new commit.
Parameters for this build job are location profiles defined in main pom.xml. Count of these profiles is static and persistent. So after every commit I need to build a project for the same profiles. One profile is started for one build.
It is able for manual triggering when I write profile name and start the build job. But after new commit this build job is started without parameters. So is there any way how to define list of parameters for build job - one parameter per one build.
An SCM change will trigger a related Jenkins job. Once. That's it.
When that job is triggered, and is configured with parameters, it does have default parameters.
For string parameters, it's the default value entered in configuration page (if you haven't entered one, the default is just that: none).
For single choice-style parameters, it's the top-most value.
For multi choice-style parameters, again, unless a default is provided in configuration, it's nothing.
If what you want is to trigger multiple runs of the same build for the same SCM change, then you've configured your jobs wrong.
Either create a matrix job, and configure an axis for every "profile" as you call it.
Or create multiple jobs, and chain them, so that first is triggered by SCM change, and the rest are triggered in sequence
If you only want to specify one default string that should be picked up while building using Poll SCM feature, then you should try using the following method:
Select the following options in Extended Choice Parameter:
In Simple Parameter Types section, go for Single Select in Parameter Type
Instead of Choose Source for Value, go for Choose Source for Default Value. Now enable the radio-button named Default Value. Enter whatever string you want to specify. Build will pick-up the given string as the default one.
Hopefully, it should work. At least, it works when i use Build periodically option. :)

How to call a jenkins Job based on User inputs

The issue here is once the first Job in a Jenkins pipeline is done, we need to ask some inputs from user and based on the user Inputs to decide the next job to be triggered(Job2 or Job3)
tried build flow and parameterzied trigger plugin but didn't find any suitable option under these.
Any other plugin or jenkins feature which can help in achieving the above scenario?
There are a few plugins I have tried which collect user input on manually triggered jobs in a build pipeline: Active Choices Plug-in 1.2 and Extensible Choice Parameter 1.3.2.
With Active Choices you define a list of selections and a default value. With Extensible Choice Parameter you can have a text box and a default value.
This is how they work for me in Build Pipeline 1.4.8 on jenkins 1.628
If you run the manual step directly in the pipeline the default is used and other parameters propagate through correctly.
If you open the step there is an option to Build with Parameters which will ask for the user input. This works but other parameters like the build number do not propagate through so the pipeline is broken, and the pipeline screen does not show the status.
Jenkins will never pause and ask a user for inputs. It is an automated build system. It doesn't expect anyone sitting at the console watching the progress.
You can provide "inputs" or parameters when you manually trigger the job, i.e on the first job in your pipeline. You can them pass these parameters to downstream jobs, either through the Parameterized Trigger plugin or through a file copied between jobs.
If you need a human decision in the middle of your build flow, consider Promoted Builds plugin. With this plugin, a human can select a build, and then decide which "Promotion" to execute (which could branch your workflow as you need). The promotions can also be automated if needed, based on criteria and not human input.

Resources