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

Access to build's own changelog from script

    XMLWordPrintable

Details

    • New Feature
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Fixed
    • pipeline
    • None

    Description

      Workflow scripts would often like to behave differently depending on the SCM changelog(s) for the current build (or perhaps a downstream build). You can use currentBuild.rawBuild.changeSets but this is not accessible from the sandbox.

      Attachments

        Issue Links

          Activity

            jglick Jesse Glick added a comment -

            Correct.

            jglick Jesse Glick added a comment - Correct.
            jamesdumay James Dumay added a comment - - edited

            jglick / hrmpw / abayer is there any reason why the change log is sandboxed? Could we offer it in some other way? e.g. request it as a JSON blob or well known array structure?

            jamesdumay James Dumay added a comment - - edited jglick / hrmpw / abayer is there any reason why the change log is sandboxed? Could we offer it in some other way? e.g. request it as a JSON blob or well known array structure?
            hrmpw Patrick Wolf added a comment -

            jglick / abayer / jamesdumay the Global Library is not sandboxed now would it be possible to put this snippet into a global library function and run it? Would currentBuild be available in a global library call?

            Likewise, plugins are not subject to the sandbox so this might be able to be solved with the "step in pipeline" work that Andrew and KK are looking at.

            hrmpw Patrick Wolf added a comment - jglick / abayer / jamesdumay the Global Library is not sandboxed now would it be possible to put this snippet into a global library function and run it? Would currentBuild be available in a global library call? Likewise, plugins are not subject to the sandbox so this might be able to be solved with the "step in pipeline" work that Andrew and KK are looking at.
            jamesdumay James Dumay added a comment -

            hrmpw thanks for that. abayer you think there is an easier way we can make this work in your new work?

            jamesdumay James Dumay added a comment - hrmpw thanks for that. abayer you think there is an easier way we can make this work in your new work?

            When trying to run this:

            node("mac") {
              env.JAVA_HOME = tool 'JDK 8'
              def buildNumber = env.BUILD_NUMBER
              def build = currentBuild
              
            ....
            
                  summarizeBuild(${build})
                  ...
            
            }
            
            @NonCPS
            def summarizeBuild(b) {
              b.changeSets.collect { cs ->
                /kind=${cs.kind}; entries=/ + cs.collect { entry ->
                  /${entry.commitId} by ${entry.author.id} ~ ${entry.author.fullName} on ${new Date(entry.timestamp)}: ${entry.msg}:  /+ entry.affectedFiles.collect { file ->
                    /${file.editType.name} ${file.path}/
                  }.join('; ')
                }.join(', ')
              }.join(' & ')
            }
            

            I always get this error:

            java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList
            	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
            	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:569)
            	at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
            	at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56
            

            Did anybody have a valid example?

            mreinhardt Martin Reinhardt added a comment - When trying to run this: node( "mac" ) { env.JAVA_HOME = tool 'JDK 8' def buildNumber = env.BUILD_NUMBER def build = currentBuild .... summarizeBuild(${build}) ... } @NonCPS def summarizeBuild(b) { b.changeSets.collect { cs -> /kind=${cs.kind}; entries=/ + cs.collect { entry -> /${entry.commitId} by ${entry.author.id} ~ ${entry.author.fullName} on ${ new Date(entry.timestamp)}: ${entry.msg}: /+ entry.affectedFiles.collect { file -> /${file.editType.name} ${file.path}/ }.join( '; ' ) }.join( ', ' ) }.join( ' & ' ) } I always get this error: java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860) at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:569) at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65) at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56 Did anybody have a valid example?

            People

              jglick Jesse Glick
              jglick Jesse Glick
              Votes:
              5 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: