Don’t use sing quotes ‘, make sure you use “, that way the string can be 
interpolated.


I also use a global helper that grabs the output of `sh` functions.

def runAndReturn(script){
  toReturn = sh(script:script, returnStdout: true)
  toReturn = toReturn[0..-2]
  println toReturn
  toReturn
}

stage('Build image') { 
    steps {
        tagBefore = runAndReturn("git describe --candidate=1 --tags")
        tag = runAndReturn("echo ${tagBefore} | cut -d\'-\' -f 1")
        webImageName = 
"${env.ACR_LOGINSERVER}/my-project-1499882073260/test:${tag}"
        sh "sudo docker build -t ${webImageName} -f 
WebApplication/WebApplication1/Dockerfile WebApplication/."
    }
}

or something like:


        stage('Build image') { 
            steps {
                sh """
                export TAG=$(git describe --candidate=1 --tags)'
                export TAG=$(echo $TAG | cut -d\'-\' -f 1)'
                export 
WEB_IMAGE_NAME=$ACR_LOGINSERVER/my-project-1499882073260/test:$TAG
                sudo docker build -t $WEB_IMAGE_NAME -f 
WebApplication/WebApplication1/Dockerfile WebApplication/.
                """            
            }
        }

First example would allow you to go through and get access to strings to have 
more control over the strings. Second is an example of how you could use it to 
stay in bash.


> On May 23, 2018, at 7:40 AM, JB <[email protected]> wrote:
> 
> Hello All,
> 
> Anyone knows how to edit a variable from shell and recover the result across 
> each next shells.
> 
> I'm trying to get the git tag version and to push the value into an env 
> variable.
> In next, I'd like to re use the value into the next cmd shell.
> 
> It doesn't work!
> 
> Anyone has an idea? I worked more than 2 days to trying to fix it.
> 
>         stage('Build image') { 
>             steps {
>                 sh 'TAG=$(git describe --candidate=1 --tags)'
>                 sh 'TAG=$(echo $TAG | cut -d\'-\' -f 1)'
>                 sh 'WEB_IMAGE_NAME=' + env['ACR_LOGINSERVER'] + 
> '/my-project-1499882073260/test:' + env['TAG']
>         
>                 sh 'sudo docker build -t ${WEB_IMAGE_NAME} -f 
> WebApplication/WebApplication1/Dockerfile WebApplication/.'                
>             }
>         }
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-users/8effa089-07c3-4918-afdd-858513ef13cc%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/jenkinsci-users/8effa089-07c3-4918-afdd-858513ef13cc%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/52ED90CD-91CF-4FA6-B39D-E0DC71B92AF9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to