Quantcast

Git commit id for a build in email-ext script

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Git commit id for a build in email-ext script

Xavier Nodet
Hello,

I am starting to use email-ext, editing the provided groovy-text. template.
In the general case, how am I supposed to determine what git ID was used for the build (assuming the build uses Git, of course...)

I know how to get this information from the latest change when there is one:

<%
def changeSet = build.changeSet
if (changeSet != null && !changeSet.isEmptySet()) {
  def lastGitId = "";
  changeSet.each() { cs ->
     lastGitId = cs.commitId
  }
  %>Git id: ${lastGitId}
<%
}

But this will only work when there are actual changes, of course...

Still, even if there are no changes, Jenkins knows what revision was used for a build.
How to go from an AbstractBuild to the git Id?

Thanks.

--
Xavier Nodet

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Git commit id for a build in email-ext script

slide


On Thu, Oct 25, 2012 at 11:44 AM, Xavier Nodet <[hidden email]> wrote:
Hello,

I am starting to use email-ext, editing the provided groovy-text. template.
In the general case, how am I supposed to determine what git ID was used for the build (assuming the build uses Git, of course...)

I know how to get this information from the latest change when there is one:

<%
def changeSet = build.changeSet
if (changeSet != null && !changeSet.isEmptySet()) {
  def lastGitId = "";
  changeSet.each() { cs ->
     lastGitId = cs.commitId
  }
  %>Git id: ${lastGitId}
<%
}

But this will only work when there are actual changes, of course...

Still, even if there are no changes, Jenkins knows what revision was used for a build.
How to go from an AbstractBuild to the git Id?

Thanks.

--
Xavier Nodet


Is it part of the build variables? build.buildVariables is a Map<String, String>.

slide

--
Website: http://earl-of-code.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Git commit id for a build in email-ext script

Xavier Nodet
On Thu, Oct 25, 2012 at 8:54 PM, Slide <[hidden email]> wrote:

On Thu, Oct 25, 2012 at 11:44 AM, Xavier Nodet <[hidden email]> wrote:
How to go from an AbstractBuild to the git Id?

Is it part of the build variables? build.buildVariables is a Map<String, String>.

The map is empty when I ask for it in the script.
build.buildVariables.size() == 0

--
Xavier Nodet

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Git commit id for a build in email-ext script

slide


On Thu, Oct 25, 2012 at 12:10 PM, Xavier Nodet <[hidden email]> wrote:
On Thu, Oct 25, 2012 at 8:54 PM, Slide <[hidden email]> wrote:

On Thu, Oct 25, 2012 at 11:44 AM, Xavier Nodet <[hidden email]> wrote:
How to go from an AbstractBuild to the git Id?

Is it part of the build variables? build.buildVariables is a Map<String, String>.

The map is empty when I ask for it in the script.
build.buildVariables.size() == 0

--
Xavier Nodet


How about using the build.variableResolver and calling the resolve method? I am not sure where this information would come from, I'm just looking at the AbstractBuild javadoc. So, perhaps someone else would have some better information :-)

slide

--
Website: http://earl-of-code.com
Loading...