0

I am using a jenkinsfile to execute commands of python, pytest and building code. My question here is that, I want to use a string parameter to run a whole command calling jenkins environment variables. I have noticed that when I run the command in the groovy, it gives me an error because it interpret the ${environment_variable} as mere string.

My jenkinsfile is:

pipeline {
    agent any 
    environment 
    {
        DUMMY = "Hello world"
    }
    stages {
        stage('Stage 1') {
            steps {
                bat"""
                ${test_command}
                """
            }
        }
    }
}

and my call for the string parameter "test_command" is:

echo ${DUMMY}

Is there any way that echo returns "Hello World" and not "${DUMMY}"?

Thanks!

GGChe
  • 133
  • 8
  • 1
    The syntax for the string interpolation needs to be valid for the Windows command interpreter. Your Jenkins Pipeline itself is completely fine here. – Matt Schuchard Nov 05 '21 at 16:24
  • Ok, I got it. The issue was a permission problem related to groovy ci stathic method. This was the solution: https://stackoverflow.com/questions/38276341/jenkins-ci-pipeline-scripts-not-permitted-to-use-method-groovy-lang-groovyobject – GGChe Nov 08 '21 at 08:10

0 Answers0