0

How do I access this variable in a shell script.

enter image description here

I have tried

  1. echo params.$STATES;
  2. echo $STATES;

Output for the first one is params. . Output for the second one is an empty string. The output I am expecting is the string I am passing when I build that job with parameters.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
Aaron
  • 1,345
  • 2
  • 13
  • 32

1 Answers1

0
  1. If you are using the 'Execute Shell' block in a Freestyle Project, you will need a $ (dollar sign) before the variable. Since you already tried this, there could be an issue not wrapping variable within {}
  1. If you are using a Jenkinsfile without a shell block (valid in Scripted and Declarative)
  • Use dollar sign with double quotes
node(){
    echo "$STATES"
}
pipeline {
    agent any
    stages {
        stage('Hello') {
            steps {
                echo "$STATES"
            }
        }
    }
}
  • or without Double quotes and dollar sign
node(){
    echo STATES
}
pipeline {
    agent any
    stages {
        stage('Hello') {
            steps {
                echo STATES
            }
        }
    }
}
  1. If you are using a Shell block in the Jenkinsfile pipeline, use sh "echo $STATES" or sh "echo ${STATES}" (as in the Freestyle Execute Shell block, Double quotes are needed for interpolation)

See

Sai
  • 15
  • 4