RamblingCookieMonster / BuildHelpers

Helper functions for PowerShell CI/CD scenarios
MIT License
214 stars 47 forks source link

Bh is pull request #117

Open FISHMANPET opened 5 years ago

FISHMANPET commented 5 years ago

fixes #79 This reads environment variables in the following CIs to set a IsPullRequest variable if the current build has been triggered by a PR: AppVeyor, Gitlab CI, Azure Pipelines, Bamboo, GoCD, Travis CI, and Github Actions. I couldn't figure out a way to determine it in Jenkins or Teamcity but if there is a reliable way that someone is aware of it's easy to see in the code where to set it.

I thought about figuring out way to determine this from Git directly but I'm not sure it's possible or even reasonable. GIt doesn't have a notion of a pull request directly it seems, in Github a pull request creates a branch something like refs/remotes/pull/2/merge but other systems may do something different so I'm not sure checking that the current branch matches a certain pattern is going to be reliable

If the build environment says the build was triggered by a PR, it says IsPullRequest to be True otherwise it won't create the variable, so you can then check for the existence of the environment variable (or $BHIsPullRequest in the case of Set-BuildVariable.ps1)

I also thought about setting some more details about the PR, like maybe the PR number, the source branch, the destination branch, etc, but I'd need help from people with experience in other CI systems to do that. I know where to find the values in my CI, Azure Pipelines, but less so in the others.

Finally, I'd added CommitHash a while ago but realized I'd never added it to Set-BuildVariable.ps1 so in addition to adding the logic for IsPullRequest in there I also added CommitHash to that file.

RamblingCookieMonster commented 4 years ago

Hiii! Awesome idea! Sorry for the delay, and for the quantity of feedback!