[JIRA] (JENKINS-60365) Environment variables not being set on post-submit

13 views
Skip to first unread message

felipecassiors@gmail.com (JIRA)

unread,
Dec 4, 2019, 7:17:02 AM12/4/19
to jenkinsc...@googlegroups.com
Felipe Santos created an issue
 
Jenkins / Bug JENKINS-60365
Environment variables not being set on post-submit
Issue Type: Bug Bug
Assignee: Luca Domenico Milanesio
Components: gerrit-code-review-plugin
Created: 2019-12-04 12:16
Environment: gerrit-code-review-plugin 0.3.7
Priority: Minor Minor
Reporter: Felipe Santos

I just started a new Jenkins, created a repo in GerritHub and set it up. When Jenkins builds the open changes, all the environment variables are being created and exposed accordingly. However, in a build of the branch such as master, none of these variables are set (only PROJECT, API_URL and CREDENTIALS_ID). 

I suppose this is what causes the gerritReview step to fail when trying to post comments on a merged change. (When using plain Pipeline with Gerrit Trigger, the gerritReview step works fine on post-submit changes).

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

luca.milanesio@gmail.com (JIRA)

unread,
Dec 5, 2019, 5:35:03 PM12/5/19
to jenkinsc...@googlegroups.com
Luca Domenico Milanesio commented on Bug JENKINS-60365
 
Re: Environment variables not being set on post-submit

True, change-related variables on a regular branch are not set.

That is due to the fact that Gerrit doesn't know what is the associated change because the branch is not pointing to a change ref.

Jenkins is typically used with Gerrit for allowing pre-commit validation. What is your use-case on a regular branch?

felipecassiors@gmail.com (JIRA)

unread,
Dec 9, 2019, 5:04:02 PM12/9/19
to jenkinsc...@googlegroups.com

That's right.

My use case: 

  • We produce a docker image for our repo on every commit and push it. For pre-submit commits, we tag it with the commit hash and the Gerrit change number. For post-submit we also does, alongside we also tag as :latest. In the end of the pipeline, we post comments on the change (gerritReview step) with a snippet for the docker pull command of that image matching the revision of the patchset. 

This comment is useful to be posted also for post-submit commits, due to the fact that the commit author can have the image name of that desired commit without having to search (not every time the last patch-set (after hitting Submit) is the same of the latest one after pushing, because it gets rebased).

However, there is another possibility the lack of these variables is depriving me:
I want to tag my docker images with the Gerrit change number even after it gets merged, and for this I need the variable GERRIT_CHANGE_NUMBER and/or GERRIT_PATCHSET_NUMBER to be set.

I'm pointing because switching from Gerrit Trigger lacks me this possibility and so far I have not found any no workaround.

felipecassiors@gmail.com (JIRA)

unread,
Dec 9, 2019, 5:06:01 PM12/9/19
to jenkinsc...@googlegroups.com
Felipe Santos edited a comment on Bug JENKINS-60365
That's right.


My use case: 
- We produce a docker image for our repo on every commit and push it. For pre-submit commits, we tag it with the commit hash and the Gerrit change number. For post-submit we also does, alongside we also tag as :latest. In the end of the pipeline, we post comments on the change (gerritReview step) with a snippet for the docker pull command of that image matching the revision of the patchset. 


This comment is useful to be posted also for post-submit commits, due to the fact that the commit author can have the image name of that desired commit without having to search (not every time the last patch-set (after hitting Submit) is the same of the latest one after pushing, because it gets rebased).

However, there is another possibility the lack of these variables is depriving me:
I want to tag my docker images with the Gerrit change number even after it gets merged, and for this I need the variable GERRIT_CHANGE_NUMBER and/or GERRIT_PATCHSET_NUMBER to be set.

I'm pointing because switching from Gerrit Trigger lacks me this possibility and so So far I have not found any no workaround.

luca.milanesio@gmail.com (JIRA)

unread,
Dec 30, 2019, 8:53:02 AM12/30/19
to jenkinsc...@googlegroups.com

luca.milanesio@gmail.com (JIRA)

unread,
Dec 30, 2019, 8:53:02 AM12/30/19
to jenkinsc...@googlegroups.com
Luca Domenico Milanesio commented on Improvement JENKINS-60365
 
Re: Environment variables not being set on post-submit

If we want to get those variables, we need to try to understand what is the change associated with a SHA1: it is feasible I believe, because Gerrit would be able to find the change number based on the SHA1 of the commit.

Changed the issue to improvement and will put it in my backlog.

Thanks for sharing your use-case.

felipecassiors@gmail.com (JIRA)

unread,
Dec 30, 2019, 9:49:02 AM12/30/19
to jenkinsc...@googlegroups.com

The approach you suggested makes a lot of sense. I might try to contribute to the code, I will have a look when I get some time. Thanks!

Reply all
Reply to author
Forward
0 new messages