Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is primary environment to branch name contributor #236

Merged
merged 9 commits into from
Feb 8, 2021

Conversation

cwholmes
Copy link
Contributor

@cwholmes cwholmes commented Nov 15, 2020

https://issues.jenkins.io/browse/JENKINS-64686
'
During a pipeline execution, it is often valuable to know whether or not the branch currently being executed is the primary branch for the scm source.

This adds an environment contribution in the branch name contributor of BRANCH_IS_PRIMARY.

When the PrimaryInstanceMetadataAction action exists for the branch this environment variable is set to "true" otherwise it is set to "false".

@AnEmortalKid
Copy link

@bitwiseman mind taking a peek at this

Copy link
Contributor

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically looks good to me.
Is there a Jenkins JIRA ticket for this? If not, please create one.

@cwholmes
Copy link
Contributor Author

This basically looks good to me.
Is there a Jenkins JIRA ticket for this? If not, please create one.

I don't believe a JIRA does exist, and I am not sure that I can create one as I don't have an account and don't seem to be able to create one at the moment.

Co-authored-by: Liam Newman <bitwiseman@gmail.com>
@AnEmortalKid
Copy link

I created https://issues.jenkins.io/browse/JENKINS-64686 for this change

@cwholmes
Copy link
Contributor Author

cwholmes commented Feb 5, 2021

@bitwiseman I have made the suggested changes, but the build is now failing on linux for the same reason as master currently. Could you take another look and possibly get this change merged?

@timja
Copy link
Member

timja commented Feb 7, 2021

@bitwiseman I have made the suggested changes, but the build is now failing on linux for the same reason as master currently. Could you take another look and possibly get this change merged?

will be fixed by: #242

@bitwiseman
Copy link
Contributor

Thanks, @timja !

@bitwiseman bitwiseman merged commit e39a004 into jenkinsci:master Feb 8, 2021
if (branch.getAction(PrimaryInstanceMetadataAction.class) != null) {
envs.put("BRANCH_IS_PRIMARY", "true");
} else {
envs.put("BRANCH_IS_PRIMARY", "false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late review/question—instead of setting it to "false" (which is a truthy string), would it be possible to set it to the empty string?

Suggested change
envs.put("BRANCH_IS_PRIMARY", "false");
envs.put("BRANCH_IS_PRIMARY", "");

This would make it easier for scripts to check this value without having to remember to convert it to a Boolean or comparing string literals. Please let me know if this makes sense, and I can open a PR.

(Hopefully it's not too late/disruptive to make this change since it looks like this hasn't been released yet. 🤞 )

Copy link
Contributor

@bitwiseman bitwiseman Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@usmonster
We haven't released since this was merged, so I'm open to changing the behavior but I'm not convinced we should. I generally think these variables being used by any number of systems, so designing specifically for shell script behavior isn't my goal. false is much clearer in my java-centric mind. Perhaps you could file a PR with the proposed change some examples and tag @cwholmes and we can discuss in a thread that isn't off the tail end of a merged PR. 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick response, @bitwiseman!

To be clear, this isn't a shell script-specific proposal, but I was thinking more about the most common context in which these variables will be used, i.e. in the Groovy scripts that define Jenkins pipelines. Maybe the variable shouldn't even be set if it's not a primary branch? In any case, I'll file a new PR to formally propose and discuss this. Thanks again!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my 2 cents is you should only be comparing for the string == "true".

imo current behaviour is fine. but 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👉 #246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants