Want to get branch or ref string from Github Web Hook on Build

12 views
Skip to first unread message

jbr...@snapapp.com

unread,
Aug 8, 2017, 3:27:39 PM8/8/17
to Jenkins Users
Hi all,

I have my GitHub web hook working on a Pipeline job, which is great! I looked at the currentBuild object and my env variables, though, and I don't appear not have access to the branch name, or ref string (e.g. refs/heads/master). I know that the ref is sent as part of a payload (https://developer.github.com/v3/activity/events/types/#pushevent), so it seems reasonable to think that Jenkins would pass this data forward somehow.

I tried looking at http://javadoc.jenkins-ci.org/hudson/scm/ChangeLogSet.Entry.html to see if currentBuild.changeSets would give me anything, but I don't see it. Does Jenkins not know how to talk about git refs? Does it just drop everything on the floor except the commits?

Cheers,
Jack

Mark Waite

unread,
Aug 8, 2017, 3:38:12 PM8/8/17
to Jenkins Users
BRANCH_NAME should have the value of the branch name in your pipeline context.


Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e30f6b41-3c60-402f-933a-f79c6d0138ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jack Brooks

unread,
Aug 8, 2017, 3:42:55 PM8/8/17
to jenkins...@googlegroups.com
Hi Mark!

Yeah, I'm not using a multibranch job in this case. Is that the idiomatic Jenkins way to do things? 

Thanks!
Jack

On Tue, Aug 8, 2017 at 3:37 PM, Mark Waite <mark.ea...@gmail.com> wrote:
BRANCH_NAME should have the value of the branch name in your pipeline context.


Mark Waite

On Tue, Aug 8, 2017 at 1:27 PM <jbr...@snapapp.com> wrote:
Hi all,

I have my GitHub web hook working on a Pipeline job, which is great! I looked at the currentBuild object and my env variables, though, and I don't appear not have access to the branch name, or ref string (e.g. refs/heads/master). I know that the ref is sent as part of a payload (https://developer.github.com/v3/activity/events/types/#pushevent), so it seems reasonable to think that Jenkins would pass this data forward somehow.

I tried looking at http://javadoc.jenkins-ci.org/hudson/scm/ChangeLogSet.Entry.html to see if currentBuild.changeSets would give me anything, but I don't see it. Does Jenkins not know how to talk about git refs? Does it just drop everything on the floor except the commits?

Cheers,
Jack

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/JvIEwuE-D8M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtGH%3DE3y%3DDOi-FrZgBxk94iG%2BcgpuKGM2ZKocHCQX3yB1A%40mail.gmail.com.

Mark Waite

unread,
Aug 8, 2017, 3:47:38 PM8/8/17
to jenkins...@googlegroups.com
If you're using a scripted pipeline, and you're using Jenkins 2.60 or later, and you're using the latest releases of the pipeline plugins, then the return value of the checkout step is a map with many useful values from the checkout, including the branch name, the SHA1, and more.

If you're using a declarative pipeline, you'll need to wait a little bit for that same information to be available to the job.  I understand that there is a concept of how to do it, but don't know if there is an implementation yet.

There is always the alternative of calling the "sh" command to read the git repository and report the branch name to stdout, then assign that stdout value to a var.

Mark Waite

On Tue, Aug 8, 2017 at 1:42 PM Jack Brooks <jbr...@snapapp.com> wrote:
Hi Mark!

Yeah, I'm not using a multibranch job in this case. Is that the idiomatic Jenkins way to do things? 

Thanks!
Jack

On Tue, Aug 8, 2017 at 3:37 PM, Mark Waite <mark.ea...@gmail.com> wrote:
BRANCH_NAME should have the value of the branch name in your pipeline context.


Mark Waite

On Tue, Aug 8, 2017 at 1:27 PM <jbr...@snapapp.com> wrote:
Hi all,

I have my GitHub web hook working on a Pipeline job, which is great! I looked at the currentBuild object and my env variables, though, and I don't appear not have access to the branch name, or ref string (e.g. refs/heads/master). I know that the ref is sent as part of a payload (https://developer.github.com/v3/activity/events/types/#pushevent), so it seems reasonable to think that Jenkins would pass this data forward somehow.

I tried looking at http://javadoc.jenkins-ci.org/hudson/scm/ChangeLogSet.Entry.html to see if currentBuild.changeSets would give me anything, but I don't see it. Does Jenkins not know how to talk about git refs? Does it just drop everything on the floor except the commits?

Cheers,
Jack

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/JvIEwuE-D8M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAAk78BQWCdhqUPqSS-XNf2p9G_8NjdPGihTPS%2BXvq27m3H7U9g%40mail.gmail.com.

Jack Brooks

unread,
Aug 8, 2017, 4:16:52 PM8/8/17
to jenkins...@googlegroups.com
Gotcha. What I was running into in the declarative pipeline instance was that I was using the git plugin to checkout changes- I think I'm seeing now that I was making more work for myself. I'll take a look at `checkout scm`, which seems like it saves me time.

Thanks!
Jack

On Tue, Aug 8, 2017 at 3:47 PM, Mark Waite <mark.ea...@gmail.com> wrote:
If you're using a scripted pipeline, and you're using Jenkins 2.60 or later, and you're using the latest releases of the pipeline plugins, then the return value of the checkout step is a map with many useful values from the checkout, including the branch name, the SHA1, and more.

If you're using a declarative pipeline, you'll need to wait a little bit for that same information to be available to the job.  I understand that there is a concept of how to do it, but don't know if there is an implementation yet.

There is always the alternative of calling the "sh" command to read the git repository and report the branch name to stdout, then assign that stdout value to a var.

Mark Waite

On Tue, Aug 8, 2017 at 1:42 PM Jack Brooks <jbr...@snapapp.com> wrote:
Hi Mark!

Yeah, I'm not using a multibranch job in this case. Is that the idiomatic Jenkins way to do things? 

Thanks!
Jack

On Tue, Aug 8, 2017 at 3:37 PM, Mark Waite <mark.ea...@gmail.com> wrote:
BRANCH_NAME should have the value of the branch name in your pipeline context.


Mark Waite

On Tue, Aug 8, 2017 at 1:27 PM <jbr...@snapapp.com> wrote:
Hi all,

I have my GitHub web hook working on a Pipeline job, which is great! I looked at the currentBuild object and my env variables, though, and I don't appear not have access to the branch name, or ref string (e.g. refs/heads/master). I know that the ref is sent as part of a payload (https://developer.github.com/v3/activity/events/types/#pushevent), so it seems reasonable to think that Jenkins would pass this data forward somehow.

I tried looking at http://javadoc.jenkins-ci.org/hudson/scm/ChangeLogSet.Entry.html to see if currentBuild.changeSets would give me anything, but I don't see it. Does Jenkins not know how to talk about git refs? Does it just drop everything on the floor except the commits?

Cheers,
Jack

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/JvIEwuE-D8M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/JvIEwuE-D8M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtGPdFniyM1G2RbTZc7rKpB_ZYi5W7P0Vb6qXUoKgdb81w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages