Score:0

Pass variable value from one build step to other in jenkins job

br flag

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

jp flag
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)
Score:0
jp flag

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} .'"
}
br flag
@jayhendren-How about this that I'm not using any pipeline code here, I'm just using jenkins build steps.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.