0

I want to pass variable value from one build step that is from 'execute shell' to 'send files or execute commands over SSH" my script in Execute shell* is:

if [ "$var" == "1"]; then
package="newpackage"
fi
if [ "$var" == "2"]; then
package="oldpackage"
fi
Given_order=${package}

send files or execute commands over SSH echo "$Given_order" but the value is not passed from execute shell build step to other. Please suggest Thanks

  • Does this answer your question? [Jenkins Pipeline File - Passing Jenkinsfile variables into further commands](https://serverfault.com/questions/884764/jenkins-pipeline-file-passing-jenkinsfile-variables-into-further-commands) – jayhendren Jan 21 '22 at 20:16

1 Answers1

0

I already answered this question here: https://serverfault.com/a/884798/213070. Basically, declare a variable in your Pipeline code out of the scope of your build stages:

def jobBaseName

stage ('Construct Img name') {
  jobBaseName = sh(
    script: "echo ${BUILD_TAG} | awk '{print tolower($0)}' | sed 's/jenkins-//'",
    returnStdout: true,
  )
}

stage ('Build Target Container') {
  sh "ssh -i ~/ssh_keys/key.key user@somehost 'cd /dockerdata/build/${BUILD_TAG} && docker build -t localrepo/${jobBaseName}:${BUILD_NUMBER} .'"
}
jayhendren
  • 917
  • 4
  • 11