Reputation: 1212
In my pipeline I have this:
steps {
script
{
def TAG_NAME = env.GIT_BRANCH.split("/")[1]
}
sshagent(credentials: ["<snip>"]) {
sh """
git tag -a "v.${TAG_NAME}.${env.BUILD_NUMBER}" -m "Add tag"
git push --tags
"""
}
}
But when this runs, I see that TAG_NAME is 'null.'
How do I make it so that I can see it in the sshagent.
Upvotes: 0
Views: 90
Reputation: 2098
A declarative pipeline example to set and get variables across the stages in a different ways .
def x
pipeline {
agent any;
stages {
stage('stage01') {
steps {
script {
x = 10
}
}
}
stage('stage02') {
steps {
sh "echo $x"
echo "${x}"
script {
println x
}
}
}
}
}
on your example, it could be
def TAG_NAME
pipeline {
agent any;
stages {
stage('stageName') {
steps {
script {
TAG_NAME = env.GIT_BRANCH.split("/")[1]
}
sshagent(credentials: ["<snip>"]) {
sh """
git tag -a "v.${TAG_NAME}.${env.BUILD_NUMBER}" -m "Add tag"
git push --tags
"""
}
}
}
}
}
Upvotes: 1