How do I identify the latest build on a branch with a parameter?

I want to get a parameter populated to help me figure out if I'm building the latest commit on a given Git branch. For example, if I'm building the latest commit on master (in other words, a non-history commit), I'd want an environment variable, `env.IS_LATEST=true`, which I could use to put the latest tag on a Docker image I'm building.

I know I can figure out what branch I'm on, but wasn't sure how to make sure I wasn't running a history build. I wouldn't want a old commit tagged as latest.

Thanks

0
2 comments

Hi Jon,

 

we don't provide a variable to check that as an env.var, but the info is available in the REST API, you can check for the app/rest/builds/?locator=buildType:<buildConfigId>,state:running

 

then pull the information and check if the build has the property "history=true".

 

Another possibility would be to just run a script that checks which commit is being built (you can gather it via the parameter %system.build.vcs.number% which will work assuming you only have 1 VCS Root, then call the history of your repo and see if it's the latest revision or not.

1

Thanks for the suggestions, I'll give that a shot!

0

Please sign in to leave a comment.