I see a bunch of closed threads here without an official response from CircleCI staff. It would be nice to 1) if this is a bug, get it fixed or at least have a clear statement on the priority and ETA 2) or deprecate it from the documentation 3) or update the documentation on what requirements need to be fulfilled to not have this variable empty.
Iām an engineer on the Pipelines team here at CircleCI. The environment variable CIRCLE_COMPARE_URL is available in v2 of our config schema, but not in v2.1. We are aware that this is a problem for some folks, and weāre working to provide an upgrade path.
For v2.1 we are introducing something we call pipeline values. You use these like job parameters, but theyāre more like constants for your pipeline. The first set of pipeline values we are introducing contains all the values you need to define your own CIRCLE_COMPARE_URL. These are available to use in production right now, but the public documentation hasnāt caught up yet.
pipeline.git.tag - the tag triggering the pipeline (if any)
pipeline.git.branch - the branch triggering the pipeline (if any)
pipeline.git.revision - the current git revision
pipeline.git.base_revision - the previous git revision (if this is a PR)
Weāll work hard to get better documentation for this out soon, I promise. In the meantime Iāve opened a PR against our docs to make it clear that CIRCLE_COMPARE_URL is not availble in 2.1, and point to this discuss post for more details.
Any chance I am experiencing this because āEnable pipelinesā is on under Advanced Settings?
Not as far as I understand. If youāre using version: 2 config and CIRCLE_COMPARE_URL is not set itās likely because we havenāt been able to capture the base (ābeforeā) revision, which we cannot get from the repo itself. We get the base revision from the webhook associated with the event. (I.e. push/pr creation.) In some cases the base revision is not available in the webhook, and we are unable to create the CIRCLE_COMPARE_URL. (Iām afraid I donāt have a full understanding of why this is yet.)
PS: if youāre able to share a link to your job for future queries that would be most helpful.
Wait, is CIRCLE_COMPARE_URL only meant to be available on pull requests? I somehow thought this also allows retrieving the commit range between the current and previous build on any branch (the same commit range that is shown on the web UI too).
PS: if youāre able to share a link to your job for future queries that would be most helpful.
Itās a private repo but if you have access as an employee itās the only repo this user has access to: https://circleci.com/gh/marton-kiro.
Hi @stig Iām trying to use the CIRCLE_COMPARE_URL code you listed. What Iām seeing for new branches is that there is no pipeline.git.base_revision . Any recommendations on how to get this compare url to work for new branches? The old CIRCLE_COMPARE_URL handled this case.
Hey @stig, I like the pipeline values a lot, but Iām wondering how youād recommend handling this particular case in an orb in v2.1. Iād like to reference the previous revision but according to this thread and the docs, canāt use CIRCLE_COMPARE_URL or pipeline.git.base_revision since pipeline values arenāt supported in orbs. Thoughts?
Iām wondering how youād recommend handling this particular case in an orb in v2.1. Iād like to reference the previous revision but according to this thread and the docs, canāt use CIRCLE_COMPARE_URL or pipeline.git.base_revision since pipeline values arenāt supported in orbs. Thoughts?
I think you have to create base_revision as an input to your orb. Something like this:
Thanks @stig, I can work with that, but I should have mentioned I was actually hoping to use the base revision as the default value. It seems like this is currently not possible?
Hi @stone-z, I donāt think itās possible, Iām afraid. If you find yourself having to explicitly pass this parameter in many places you may be able to use an env_var_name parameter instead, cf https://circleci.com/docs/2.0/reusing-config/#environment-variable-name ā and set an environment variable in your primary configās executor/job. That should be picked up by the Orb.
thanks for sharing the example but it doesnāt work if I create a new branch and push commit to this branch, << pipeline.git.base_revision >> is empty:
our current problem is that the COMPARE_URL does not take into account the full branch/pull request, only the current and last commit
This is still a blocker for us as well, even using base_revision.
My use case is to run static code analysis on a branch before merging it, but running against the entire history takes a prohibitively long time. To reduce the scope to only the changes in the PR, I want to only scan back to the earliest common ancestor between my PR branch and the target branch (this might include scanning other branches along the way).
However, as far as I can tell, thereās no way to determine this natively from inside CircleCI.