Thank you for your advice. I tried the following script. import groovy.transform.Field @Field def value1 = 'initial value'
But the prompted value is "initial value" , which is the same value as before. 2020年11月26日木曜日 23:05:50 UTC+9 [email protected]: > You can try with environment variables or the Field annotation as shown > below > > import groovy.transform.Field > @Field def value1 = 'initial value' > > > On Wednesday, 25 November 2020 at 19:00:24 UTC Kiyoshi Ohgishi wrote: > >> 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/58c0b7e4-4083-40b2-940a-ff32b8b11c53n%40googlegroups.com.
