Chanafot
Chanafot

Reputation: 806

sh command in groovy Jenkinsfile in multiple lines

Hey folks I want to execute a sh command in a jenkinsfile which is pretty long, into multiple lines. thing is I´m unable to do so. command gets executed but only first line. I tried with "\" with "+" but i´m unable to execute the hole command. this is how I have it right now:

node {

      stage('purge URL content in cloudflare') {

        sh """\
        curl -X GET "https://api.cloudflare.com/client/v4/zones/cd7d030xxxxxxx420df9514dad0" +
        -H "X-Auth-Email: [email protected]" +
        -H "X-Auth-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
        -H "Content-Type: application/json" +
        --data '{"files":["${params.URL1}",{"url":"${params.URL2}","headers":{"Origin":"cloudflare.com","CF-IPCountry":"US","CF-Device-Type":"desktop"}}]}' """


    }



}

But I´m getting error enter image description here

How is it in groovy that you can add one command in multiple lines?

Upvotes: 2

Views: 4897

Answers (1)

A. Alencar
A. Alencar

Reputation: 151

There's no need to use + to concatenate strings in a triple-double-quoted string:

node {

  stage('purge URL content in cloudflare') {

    sh """
    curl -X GET "https://api.cloudflare.com/client/v4/zones/cd7d030xxxxxxx420df9514dad0"
    -H "X-Auth-Email: [email protected]"
    -H "X-Auth-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    -H "Content-Type: application/json"
    --data '{"files":["${params.URL1}",{"url":"${params.URL2}","headers":{"Origin":"cloudflare.com","CF-IPCountry":"US","CF-Device-Type":"desktop"}}]}' 
       """
  }
}

Source: http://groovy-lang.org/syntax.html#_triple_double_quoted_string

Upvotes: 3

Related Questions