Timothy T.
Timothy T.

Reputation: 1091

String interpolation and concatenation for Jenkinsfile

I am trying to setup a Jenkinsfile that gets a job to call other jobs, based on the parameters passed into itself.

Instead of having multiple when conditions, I'm thinking that it would be smarter (and manageable for future scaling) if the names of the jobs being called would ideally be concatenating a common prefix with the parameter being passed in, for example:

I'm having difficulty mixing string interpolation with string concatenation to achieve this:

    build job: 'CICD_"${params.SERVICE_NAME}"', wait : false

In Linux, we are able to use eval to achieve this. I'm not sure what the equivalent is in Jenkinsfile syntax.

The full code below:

pipeline {
    agent any

    parameters { string(name: 'SERVICE_NAME', defaultValue: '', description: 'Service being deployed.') }

    stages {
        stage('Build Trigger'){
            steps{
                echo "CICD_${params.SERVICE_NAME}"
                build job: 'CICD_"${params.SERVICE_NAME}"', wait : false
            }
        }
    }
}

Upvotes: 0

Views: 5291

Answers (1)

Sam
Sam

Reputation: 2882

Change it to be a Gstring from the beginning, no need for the single quotes:

build job: "CICD_${params.SERVICE_NAME}", wait : false

Upvotes: 2

Related Questions