Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Pipeline: "input" step blocks executor

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.

like image 324
Theodor Avatar asked Jun 15 '16 09:06

Theodor


People also ask

What is input in Jenkins pipeline?

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.

How do you pass parameters in Jenkins pipeline?

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.

Can we run a step conditionally in Jenkins?

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.

What are the 3 types of pipelines in Jenkins?

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.


1 Answers

EDIT (Oct 2016): Please see my other answer "Use milestone and lock" below, which includes recently introduced features.

Use timeout Step

As 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.

Move input Step to Flyweight Executor

Another 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.

like image 177
StephenKing Avatar answered Sep 22 '22 06:09

StephenKing