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

Access to build's own changelog from script

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: pipeline
    • Labels:
      None
    • Similar Issues:

      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

            Hide
            jglick Jesse Glick added a comment -

            Correct.

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

            Jesse Glick / Patrick Wolf / Andrew Bayer 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?

            Show
            jamesdumay James Dumay added a comment - - edited Jesse Glick / Patrick Wolf / Andrew Bayer 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?
            Hide
            hrmpw Patrick Wolf added a comment -

            Jesse Glick / Andrew Bayer / James Dumay 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.

            Show
            hrmpw Patrick Wolf added a comment - Jesse Glick / Andrew Bayer / James Dumay 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.
            Hide
            jamesdumay James Dumay added a comment -

            Patrick Wolf thanks for that. Andrew Bayer you think there is an easier way we can make this work in your new work?

            Show
            jamesdumay James Dumay added a comment - Patrick Wolf thanks for that. Andrew Bayer you think there is an easier way we can make this work in your new work?
            Hide
            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?

            Show
            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

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

                Dates

                • Created:
                  Updated:
                  Resolved: