0

I am trying to execute a shell command in my jenkinsfile but the variables that i set arent showing up in the shell command I am trying to execute. here is my code:

def branchName = BRANCH_NAME
def newBranchName = branch name.split('/')[1]

pipeline {
    agent any
    stages {
        stage ('build') {
            steps {
                sh 'docker build -t 771225398400.dkr.ecr.us-west-2.amazonaws.com/nics/em-api:$newBranchName .'
            }
        }
    }
}

This outputs

docker build -t 771225398400.dkr.ecr.us-west-2.amazonaws.com/nics/em-api: .

However, When I simply run a "println($newBranchName)", the correct String is printed. Any clue as to why the variables dont appear? Any help is appreciated.

Thanks!

giturr14
  • 33
  • 9

2 Answers2

0

Use double quote but single quote around your sh script. More detail

sh "docker build -t 771225398400.dkr.ecr.us-west-2.amazonaws.com/nics/em-api:$newBranchName ."
yong
  • 13,357
  • 1
  • 16
  • 27
0

Another alternative is:

    sh '''
    docker build -t 771225398400.dkr.ecr.us-west-2.amazonaws.com/nics/em-api:$newBranchName .
    '''
Miguel Conde
  • 813
  • 10
  • 22