Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-58952

sh labels can't be used in post stages

    XMLWordPrintable

Details

    Description

      When I try to assign a label to an sh step in a post stage I get an error. I.e.:

                          post {
                             always {
                                  sh label: "Collect artifacts and tear down",
                                     script '''set -ex
      

      I get the error:

      WorkflowScript: 1078: Expected a step @ line 1078, column 29.
                                     sh label: "Collect artifacts and tear down",
                                     ^
      

      This works in a build step though:

                      stage('Build') {
                          when {
                              beforeAgent true
                              expression { return env.QUICKBUILD == '1' }
                          }
                          agent {
                              dockerfile {
                                  filename 'Dockerfile'
                                  dir 'utils/docker'
                                  label 'docker_runner'
                                  additionalBuildArgs '--build-arg UID=$(id -u) --build-arg JENKINS_URL=' +
                                                      env.JENKINS_URL +
                                                       " --build-arg CACHEBUST=${currentBuild.startTimeInMillis}"
                              }
                          }
                          steps {
                               githubNotify credentialsId: 'daos-jenkins-commit-status',
                                            description: env.STAGE_NAME,
                                            context: "build" + "/" + env.STAGE_NAME,
                                            status: "PENDING"
                              checkoutScm withSubmodules: true
                              catchError(stageResult: 'UNSTABLE', buildResult: 'SUCCESS') {
                                  sh label: env.STAGE_NAME,
                                     script: '''rm -rf artifacts/sles12.3/
      

       

      Attachments

        Activity

          If I put the label after the script

                                      sh script: '''set -ex
                                                ...''',
                                      label: "Collect artifacts and tear down"
          

          it parses fine.

          brianjmurrell Brian J Murrell added a comment - If I put the label after the script sh script: '''set -ex ...''', label: "Collect artifacts and tear down" it parses fine.

          People

            Unassigned Unassigned
            brianjmurrell Brian J Murrell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: