Is CIRCLE_COMPARE_URL still a thing?

Hi there,

I came here after reading the documentation on CIRCLE_COMPARE_URL and then realizing it is left empty on all builds in my case.

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.

Thanks!

Hi @salomvary,

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.

jobs:
  my-job:
    environment:
      CIRCLE_COMPARE_URL: << pipeline.project.git_url >>/compare/<< pipeline.git.base_revision >>..<<pipeline.git.revision>>

The full set of pipeline values available today are:

  • pipeline.id - a globally unique id representing the pipeline
  • pipeline.number - a project unique integer id for the pipeline
  • pipeline.project.git_url - e.g. https://github.com/circleci/circleci-docs
  • pipeline.project.type - e.g. “github”
  • 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.

1 Like

Hello @stig, thanks for the quick reply!

My config seems to be using version: 2 not 2.1. Still, CIRCLE_COMPARE_URL is empty.

Any chance I am experiencing this because “Enable pipelines” is on under Advanced Settings?

Btw the pipeline values solution seems promising!

1 Like

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.

Yes, CIRCLE_COMPARE_URL should be available when you push new commits to an existing branch.

Pipeline variables documentation is now live: https://circleci.com/docs/2.0/pipeline-variables/ :tada:

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.

Thanks

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?

https://circleci.com/docs/2.0/pipeline-variables/#the-scope-of-pipeline-parameters

Hi @stone-z,

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:

version: 2.1

orbs:
  inline-orb:
    jobs:
      hi:
        docker:
          - image: circleci/clojure:lein-2.9.1
        parameters:
          base_revision:
            type: string
            default: "HEAD"
        steps:
          - run: echo "Hi from inline orb @ <<parameters.base_revision>>"

workflows:
  welcome:
    jobs:
      - inline-orb/hi:
          base_revision: << pipeline.git.base_revision >>

In my test project this results in:

Hope this helps!

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.

Hi @stig,

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:

It works if I push commit directly to master only.

Is there a way to make it work when I push commit to other branches? Thank you!

Check this for a working example of COMPARE_URL using pipeline variables

our current problem is that the COMPARE_URL does not take into account the full branch/pull request, only the current and last commit

more info here https://twitter.com/sseraphini/status/1280276957935083522

and https://twitter.com/sseraphini/status/1280274128751276032

anybody solved this using another approach?

2 Likes

Thanks for posting this. This is a cool approach!

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.

Would be nice to see this implemented https://ideas.circleci.com/ideas/CCI-I-894

For those in a similar situation, we wound up moving this part of our pipeline to a GitHub Action.