Discussion:
env variable to be set across jenkinfile for each step
n***@gmail.com
2018-10-19 20:58:51 UTC
Permalink
Hi,
I have the following steps in my jenkinsfile that work pretty well with
$GIT_VER=some number in the following step only.

stage('Git Checkout') {
steps {
git(url: 'ssh://mygit/my.git', branch: 'develop')
sh '''export GIT_VER=$(git tag -l [0-9].* --points-at
origin/develop | tail -n1)

When I add another step in my jenkinsfile environment variable $GIT_VER is
blank. Is there a way to set this variable so it applies to each step in
Jenkinfile?

Thank you for looking into this issue for me.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1482d40a-9e94-4e62-b548-6f91ab469e28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Slide
2018-10-19 23:45:55 UTC
Permalink
You want to do something like this:

def GIT_VER = sh(returnStdout: true, script: 'git tag... | tail -n1')

Each invocation of sh will have it's own environment space.
Post by n***@gmail.com
Hi,
I have the following steps in my jenkinsfile that work pretty well with
$GIT_VER=some number in the following step only.
stage('Git Checkout') {
steps {
git(url: 'ssh://mygit/my.git', branch: 'develop')
sh '''export GIT_VER=$(git tag -l [0-9].* --points-at
origin/develop | tail -n1)
When I add another step in my jenkinsfile environment variable $GIT_VER is
blank. Is there a way to set this variable so it applies to each step in
Jenkinfile?
Thank you for looking into this issue for me.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/1482d40a-9e94-4e62-b548-6f91ab469e28%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/1482d40a-9e94-4e62-b548-6f91ab469e28%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVevypbb4%3D19urxE1bAhCpfW%2BX3iKcJZ1Zm%3DrWyqYnZU2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
n***@gmail.com
2018-10-29 03:50:16 UTC
Permalink
Thank you for your reply.

I did try what you had suggested, but it did not work. But i could be doing
something wrong as well.

Here is my step.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
git(url: 'ssh://my.git', branch: 'testing', changelog: true)
//git(url: 'ssh://my.git', branch: 'testing')
//def GIT_VERSION=$(git tag -l [0-9].* --points-at origin/testing
| tail -n1)
//def GIT_VERSION = sh(returnStdout: true, script: 'git tag -l
[0-9].* --points-at testing | tail -n1')
sh '''
export GIT_VERSION=$(git tag -l [0-9].* --points-at origin/testing | tail
-n1)
echo $GIT_VERSION'''
}
}
}
}

stage('Parallel Deployment') {
parallel {
stage('Deployments') {
steps {
sh '''echo "Package deployment to all servers"
echo $GIT_VERSION'''
}
}
stage('server1') {
steps {
sh '''scp myapp-${GIT_VER}-${BUILD_NUMBER}.build'''
}
}
stage('server2') {
steps {
sh '''scp myapp-${GIT_VER}-${BUILD_NUMBER}.build'''
}
}
}
}
}

Basically I need to get $GIT_VER into my parallel step.

Thanks for looking into this.

Regards,
Post by Slide
def GIT_VER = sh(returnStdout: true, script: 'git tag... | tail -n1')
Each invocation of sh will have it's own environment space.
Post by n***@gmail.com
Hi,
I have the following steps in my jenkinsfile that work pretty well with
$GIT_VER=some number in the following step only.
stage('Git Checkout') {
steps {
git(url: 'ssh://mygit/my.git', branch: 'develop')
sh '''export GIT_VER=$(git tag -l [0-9].* --points-at
origin/develop | tail -n1)
When I add another step in my jenkinsfile environment variable $GIT_VER
is blank. Is there a way to set this variable so it applies to each step
in Jenkinfile?
Thank you for looking into this issue for me.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/1482d40a-9e94-4e62-b548-6f91ab469e28%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/1482d40a-9e94-4e62-b548-6f91ab469e28%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3381cf00-78a3-430d-aeaf-9cbe0b0fc209%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...