jenkins pipeline: multiline shell commands with pipe

前端 未结 3 486
青春惊慌失措
青春惊慌失措 2021-01-07 16:51

I am trying to create a Jenkins pipeline where I need to execute multiple shell commands and use the result of one command in the next command or so. I found that wrapping t

3条回答
  •  不要未来只要你来
    2021-01-07 17:11

    I tried entering all these commands in the jenkins snippet generator for pipeline and it gave the following output:

    sh '''         echo "Executing Tests"
             URL=`curl -s "http://localhost:4040/api/tunnels/command_line" | jq -r \'.public_url\'`
             echo $URL
             RESULT=`curl -sPOST "https://api.ghostinspector.com/v1/suites/[redacted]/execute/?apiKey=[redacted]&startUrl=$URL" | jq -r \'.code\'`
             echo $RESULT
    '''
    

    Notice the escaped single quotes in the commands jq -r \'.public_url\' and jq -r \'.code\'. Using the code this way solved the problem

    UPDATE: : After a while even that started to give problems. There were certain commands executing prior to these commands. One of them was grunt serve and the other was ./ngrok http 9000. I added some delay after each of these commands and it solved the problem for now.

提交回复
热议问题