I want to change from scripted pipeline script to declarative pipeline 
script.
But I have one problem defaultValue of input cannot change value in case of 
declarative pipeline script.

Below is the scripted pipeline script I want to change from.
----
def value1 = 'initial value'
node {
    label 'master'
    stage('prediction') {
        value1 = sh(script: 'echo predicted value', returnStdout: 
true).trim()
    }
}
def setting
stage('setting') {
    setting = input(parameters: [string(name: 'value2', defaultValue: 
value1)])
}
stage('execution') {
    build(job: 'job', parameters: [string(name: 'value2', value: setting)])
}
----
The prompted value in input step is "predicted value"  as I exected.

Below is the failing declarative pipeline script I tried.
----
def value1 = 'initial value'
pipeline {
    agent none
    stages {
        stage('prediction') {
            agent {
                label 'master'
            }
            steps {
                script {
                    value1 = sh(script: 'echo predicted value', 
returnStdout: true).trim()
                }
            }
        }
        stage('execution') {
            input {
                message 'setting'
                parameters {
                    string(name: 'value2', defaultValue: value1)
                }
            }
            steps {
                build(job: 'job', parameters: [string(name: 'value2', 
value: value2)])
            }
        }
    }
}
----
The prompted value is "initial value"  as I don't expect.

What I want to make with a script is the following three steps.
1. get "predicted value" using shell script in the git repository.
2. prompt "predicted value" and decide value.
3. run the job with decided value.

How to change defaultValue of input in case of declarative pipeline script?

Kiyoshi Ohgishi

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/3cd83b52-7c00-4276-ba2b-5ba0188c0301n%40googlegroups.com.

Reply via email to