Passing information between pipeline stages?

405 views
Skip to first unread message

Bent Terp

unread,
Nov 21, 2016, 4:03:28 AM11/21/16
to Jenkins Users
Hi,

trying to get started with pipelines and am having difficulties combining "input" and "stage" steps.


If I wrap a stage around the output node, it still works as intended but the UI is a little cludgy as I need to go to the build's dropdown menu to provide the input.

The user interface becomes much nicer if I also wrap the input in a separate stage so it shows up in the Stage View, but then the output stage breaks. It looks like the information is lost between stages, can this somehow be circumvented?

If I run this pipeline (no, the default values are not real ones):

stage('input') {
    def userInput = input(
        id: 'userInput', message: 'AWS Credentials?', parameters: [
            [$class: 'TextParameterDefinition', defaultValue: 'ASIAILTN6HUOSJUT5NRA', description: 'AWS Access Key ID', name: 'AWS_ACCESS_KEY_ID'],
            [$class: 'TextParameterDefinition', defaultValue: 'z4aiU9IALIahLhY0nX2tzzj2RO6DvObWD0LDf6V9', description: 'AWS Secret Access Key', name: 'AWS_SECRET_ACCESS_KEY']
    ]) 
}

stage('output') {
    node {
        sh 'export'
        echo ("AWS Acess Key ID: "+userInput['AWS_ACCESS_KEY_ID'])
        echo ("AWS Secret Access Key: "+userInput['AWS_SECRET_ACCESS_KEY'])
    }
}

then the output fails, and the console output contains this:

export USER="jenkins"
export WORKSPACE="/var/lib/jenkins/workspace/test"
export XFILESEARCHPATH="/usr/dt/app-defaults/%L/Dt"
export _="/var/lib/jenkins/workspace/test@tmp/durable-5928a78d/script.sh"
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: userInput for class: groovy.lang.Binding
	at groovy.lang.Binding.getVariable(Binding.java:63)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:224)
	at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)

with kind regards,
  Bent Terp

Björn Pedersen

unread,
Nov 21, 2016, 8:50:08 AM11/21/16
to Jenkins Users
Hi,

Would guess that this just a scope problem, see http://groovy.329449.n5.nabble.com/script-scoping-question-td355887.html for some more info.

Björn


Bent Terp

unread,
Nov 22, 2016, 9:33:13 AM11/22/16
to Jenkins Users
Of course, you were totally right - even without knowing Groovy I should have figured it out myself - just define the globals outside the stages, doh!

def userInput = null

stage('input') {
    userInput = input(
.....
Reply all
Reply to author
Forward
0 new messages