After going through the pipeline and Jenkinsfile documentation, I am a bit confused on how to create a Stage -> Production pipeline.
One way is to use the input
step like
node() { stage 'Build to Stage' sh '# ...' input 'Deploy to Production' stage 'Build to Production' sh '# ...' }
This seems a bit clunky, as this will block an executor all the time until you want to deploy to production. Is there any alternative way of being able to deploy to production, from Jenkins.
input : Wait for interactive input. This step pauses Pipeline execution and allows the user to interact and control the flow of the build. Only a basic "proceed" or "abort" option is provided in the stage view. You can optionally request information back, hence the name of the step.
Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.
The Conditional BuildStep plugin lets users add conditional logic to Freestyle jobs from within the Jenkins web UI. It does this by: Adding two types of Conditional BuildStep ("Single" and "Multiple") - these build steps contain one or more other build steps to be run when the configured condition is met.
Declarative versus Scripted Pipeline syntax Declarative and Scripted Pipelines are constructed fundamentally differently. Declarative Pipeline is a more recent feature of Jenkins Pipeline which: provides richer syntactical features over Scripted Pipeline syntax, and.
EDIT (Oct 2016): Please see my other answer "Use milestone and lock" below, which includes recently introduced features.
timeout
StepAs first option, you can wrap your sh
step into a timeout
step.
node() { stage 'Build to Stage' { sh '# ...' } stage 'Promotion' { timeout(time: 1, unit: 'HOURS') { input 'Deploy to Production?' } } stage 'Deploy to Production' { sh '# ...' } }
This stops the build after the timeout.
input
Step to Flyweight ExecutorAnother option is to not allocate a heavyweight executor for the input
step. You can do this by using the input
step outside of the node
block, like this:
stage 'Build to Stage' { node { sh "echo building" stash 'complete-workspace' } } stage 'Promotion' { input 'Deploy to Production?' } stage 'Deploy to Production' { node { unstash 'complete-workspace' sh "echo deploying" } }
This is was probably the more elegant way, but can still be combined with the timeout
step.
EDIT: As pointed out by @amuniz, you have to stash/unstash the contents of the workspace, as different nodes respectively workspace directories might be allocated for the two node
steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With