Search code examples
jenkinsjenkins-pipeline

How to access build job properties changeSets in jenkins?


We want to access build job properties changeSets item in Jenkins pipeline. To generate this scenario please follow below steps:

  1. On jenkins pipeline, call a job of freestyle project.

  2. Under that job we have used TFS source control and MSBuild plugin to build .csproj.

  3. On jenkins pipeline set code as below, to access build job properties:

    def eJob= build job: "DotNetAppProj", wait: true
    
  4. Now we want to access eJob.changeSets and its all methods/propeties.

Kindly suggest solution for this. Thanks in advance.


Solution

  • Are you wanting an example of how to use the changeSets member variable?

    If so, the following will get the first commit in the "DotNetAppProj" and display the username and commmit message.

    node {
      def eJob= build job: "DotNetAppProj", wait: true
      if(eJob.changeSets.size() > 0 && eJob.changeSets.items.size() > 0) {
        echo eJob.changeSets[0].items[0].author.fullName
        echo eJob.changeSets[0].items[0].msg
      }
    }
    

    For a complete list of member variables other than msg and author, see the ChangeLogSet.Entry.