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

Plugin should provide GIT_COMMIT_MESSAGE as Environment Variable

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: git-plugin
    • Labels:
      None
    • Similar Issues:

      Description

      We often need to do decision making on base of commit message like if commit message contains WIP so build process should not start.

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment - - edited

          This is already available for Pipeline jobs by using the GIT_COMMIT (sha1 of the commit) value returned in the map of the checkout step. Use that SHA1 to call a shell step and read the commit message into your Pipeline.

              branch = 'JENKINS-50401'
              checkout_result = checkout([$class: 'GitSCM',
                          branches: [[name: branch]],
                          extensions: [[$class: 'CloneOption', honorRefspec: true, noTags: true],
                                       [$class: 'LocalBranch', localBranch: branch]
                                      ],
                          userRemoteConfigs: [[refspec: "+refs/heads/${branch}:refs/remotes/origin/${branch}", 
                                                              url: 'https://github.com/MarkEWaite/jenkins-bugs.git']]])
              commit_message = sh(returnStdout: true, script: "git log -n 1 ${checkout_result.GIT_COMMIT}")
          

          If that same information is needed in a Freestyle project, you'll need to use a similar technique from within the build script.

          Show
          markewaite Mark Waite added a comment - - edited This is already available for Pipeline jobs by using the GIT_COMMIT (sha1 of the commit) value returned in the map of the checkout step. Use that SHA1 to call a shell step and read the commit message into your Pipeline. branch = 'JENKINS-50401' checkout_result = checkout([$class: 'GitSCM', branches: [[name: branch]], extensions: [[$class: 'CloneOption', honorRefspec: true, noTags: true], [$class: 'LocalBranch', localBranch: branch] ], userRemoteConfigs: [[refspec: "+refs/heads/${branch}:refs/remotes/origin/${branch}", url: 'https://github.com/MarkEWaite/jenkins-bugs.git']]]) commit_message = sh(returnStdout: true, script: "git log -n 1 ${checkout_result.GIT_COMMIT}") If that same information is needed in a Freestyle project, you'll need to use a similar technique from within the build script.
          Hide
          imranrazakhan imran khan added a comment -

          How to access it in declarative pipeline where checkout done implicitly. I know we can over ride this behaviour. But it would be nice to get this variable out of box.

          Show
          imranrazakhan imran khan added a comment - How to access it in declarative pipeline where checkout done implicitly. I know we can over ride this behaviour. But it would be nice to get this variable out of box.
          Hide
          markewaite Mark Waite added a comment - - edited

          Refer to the Jenkins Minute video that shows how to use the GIT_COMMIT id in a shell step. Use that GIT_COMMIT value from the declarative Pipeline to call

          git log -n 1 ${GIT_COMMIT}
          
          Show
          markewaite Mark Waite added a comment - - edited Refer to the Jenkins Minute video that shows how to use the GIT_COMMIT id in a shell step. Use that GIT_COMMIT value from the declarative Pipeline to call git log -n 1 ${GIT_COMMIT}
          Hide
          imranrazakhan imran khan added a comment -

          Till the time we didnt get GIT_COMMIT_MESSAGE, Following step will work in declarative jenkins piepline

          GIT_MESSAGE = powershell (returnStdout: true, script: 'git log -1 --format=%B ${GIT_COMMIT}').trim()

          Show
          imranrazakhan imran khan added a comment - Till the time we didnt get GIT_COMMIT_MESSAGE, Following step will work in declarative jenkins piepline GIT_MESSAGE = powershell (returnStdout: true, script: 'git log -1 --format=%B ${GIT_COMMIT}').trim()

            People

            • Assignee:
              Unassigned
              Reporter:
              imranrazakhan imran khan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: