Search code examples
jenkinsjenkins-pipelinejenkins-declarative-pipeline

Is `input` a directive or a step


The input directive on a stage allows you to prompt for input, using the input step. ..

(cit. Pipeline Syntax, Jenkins User Documentation https://jenkins.io/doc/book/pipeline/syntax/#input)

So is input actually a directive, or a step? How to understand phrase "using the input step"

Pipeline used here (extract):

stage('StageName') {
    when { environment name: 'VAR1', value: 'true' }
    steps {
        input {
            message: "press OK to continue"
        }
        dir('doithere') {
            git url: gitcoord[0], branch: gitcoord[1], credentialsId: gitcoord[2] 
            cmd('ls -alh') 
        }
    }
}

Run-time:

WorkflowScript: 336: Expected a step @ line 336, column 34.
                       message: "press OK to continue"
                                ^

Solution

  • In declarative pipeline, you have to put it directly below the stage level ("directive"). Then it is in the form input { .. }.

    In scripted pipelines (or script blocks in declarative pipelines), it exists as a normal step. The syntax then is input(..):

    stage('StageName') {
        when { environment name: 'VAR1', value: 'true' }
        steps {
            dir('doithere') {
                git url: gitcoord[0], branch: gitcoord[1], credentialsId: gitcoord[2] 
                cmd('ls -alh') 
                input(message: "press OK to continue")
                cmd('rm -rf *')
            }
        }
    }