2

I have the following DSL code and I´m getting error on line 13, $class. I guess than everything inside script("""...""") is parsed as plain text to the pipeline definition but I don´t know what´s wrong or how to escape the $ character.

My code:

pipelineJob('DSL-Test') {

parameters {
    choiceParam ('version', ['1.2.1', '1.2.0'], 'Docker Version')
}

definition {
    cps {
        sandbox(boolean sandbox = true)
        script("""
            node ('master'){
                stage('Git Checkout'){
                    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'mycrednetial', url: 'myurl']]])
                }
            }
        """.stripIndent()) 
         }
    }
}

This is the error I get:

Processing provided DSL script ERROR: startup failed: script: 13: unexpected token: class @ line 13, column 24. checkout([$class: 'GitSCM']) ^

1 error

Started calculate disk usage of build Finished Calculation of disk usage of build in 0 seconds Started calculate disk usage of workspace Finished Calculation of disk usage of workspace in 0 seconds Finished: FAILURE

Does anyone know how to make that character not display error?

Dan Cornilescu
  • 6,780
  • 2
  • 21
  • 45
joudaon
  • 93
  • 2
  • 8

1 Answers1

0

I have just managed how to escape characters.

The solution is to add: "\" before the character.

checkout([\$class:....
joudaon
  • 93
  • 2
  • 8