# Is CIRCLE\_COMPARE\_URL still a thing?

**URL:** <https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366>\
**Category:** Bug Reports\
**Created:** [November 13, 2019, 9:55am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366 "2019-11-13T09:55:07Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![salomvary](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/salomvary/32/23637_2.png) [@salomvary](https://discuss.circleci.com/u/salomvary)\
**Post date:** [November 13, 2019, 9:55am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/1 "2019-11-13T09:55:07Z")

</div>

Hi there,

I came here after reading the [documentation on `CIRCLE_COMPARE_URL`](https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables) 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!

---

<div class="post-metadata">

**Author:** ![stig](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/stig/32/25107_2.png) [@stig](https://discuss.circleci.com/u/stig)\
**Post date:** [November 13, 2019, 6:27pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/2 "2019-11-13T18:27:40Z")

</div>

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](https://circleci.com/docs/2.0/reusing-config/#parameter-syntax), 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](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](https://github.com/circleci/circleci-docs/pull/3925) to make it clear that `CIRCLE_COMPARE_URL` is not availble in 2.1, and point to this discuss post for more details.

---

<div class="post-metadata">

**Author:** ![salomvary](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/salomvary/32/23637_2.png) [@salomvary](https://discuss.circleci.com/u/salomvary)\
**Post date:** [November 13, 2019, 7:06pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/3 "2019-11-13T19:06:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![salomvary](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/salomvary/32/23637_2.png) [@salomvary](https://discuss.circleci.com/u/salomvary)\
**Post date:** [November 13, 2019, 7:07pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/4 "2019-11-13T19:07:43Z")

</div>

Btw the pipeline values solution seems promising!

---

<div class="post-metadata">

**Author:** ![stig](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/stig/32/25107_2.png) [@stig](https://discuss.circleci.com/u/stig)\
**Post date:** [November 14, 2019, 10:26am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/5 "2019-11-14T10:26:10Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![salomvary](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/salomvary/32/23637_2.png) [@salomvary](https://discuss.circleci.com/u/salomvary)\
**Post date:** [November 15, 2019, 7:25pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/6 "2019-11-15T19:25:17Z")

</div>

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](https://circleci.com/gh/marton-kiro).

---

<div class="post-metadata">

**Author:** ![stig](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/stig/32/25107_2.png) [@stig](https://discuss.circleci.com/u/stig)\
**Post date:** [November 18, 2019, 5:47pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/7 "2019-11-18T17:47:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stig](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/stig/32/25107_2.png) [@stig](https://discuss.circleci.com/u/stig)\
**Post date:** [November 22, 2019, 10:48am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/8 "2019-11-22T10:48:50Z")

</div>

Pipeline variables documentation is now live: [https://circleci.com/docs/2.0/pipeline-variables/](https://circleci.com/docs/2.0/pipeline-variables/) 🎉

---

<div class="post-metadata">

**Author:** ![iamnader](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/iamnader/32/23740_2.png) [@iamnader](https://discuss.circleci.com/u/iamnader)\
**Post date:** [December 4, 2019, 5:01pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/9 "2019-12-04T17:01:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stone-z](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@stone-z](https://discuss.circleci.com/u/stone-z)\
**Post date:** [February 17, 2020, 7:51am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/10 "2020-02-17T07:51:02Z")

</div>

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](https://circleci.com/docs/2.0/pipeline-variables/#the-scope-of-pipeline-parameters)

---

<div class="post-metadata">

**Author:** ![stig](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/stig/32/25107_2.png) [@stig](https://discuss.circleci.com/u/stig)\
**Post date:** [February 17, 2020, 2:42pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/11 "2020-02-17T14:42:42Z")

</div>

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:

```yaml
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:

 ![Screenshot 2020-02-17 at 14.42.01.png](https://global.discourse-cdn.com/circleci/original/3X/e/4/e45e7b2d55fc65f655c1a116b038e793cf392de2.png)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![stone-z](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@stone-z](https://discuss.circleci.com/u/stone-z)\
**Post date:** [February 19, 2020, 6:38am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/12 "2020-02-19T06:38:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![stig](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/stig/32/25107_2.png) [@stig](https://discuss.circleci.com/u/stig)\
**Post date:** [February 19, 2020, 5:18pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/13 "2020-02-19T17:18:23Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![alexbod](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/alexbod/32/25066_2.png) [@alexbod](https://discuss.circleci.com/u/alexbod)\
**Post date:** [June 2, 2020, 1:44pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/14 "2020-06-02T13:44:18Z")

</div>

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:

 ![Screen Shot 2020-06-02 at 4.42.05 PM](https://global.discourse-cdn.com/circleci/original/3X/7/3/733500bd5bb0ed68bb091a4b8449d5cfc1f62230.png) 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!

---

<div class="post-metadata">

**Author:** ![sibelius](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sibelius/32/13734_2.png) [@sibelius](https://discuss.circleci.com/u/sibelius)\
**Post date:** [July 6, 2020, 11:11pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/15 "2020-07-06T23:11:08Z")

</div>

Check this for a working example of COMPARE\_URL using pipeline variables

> <https://github.com/sibelius/monorepo-101/pull/6>

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](https://twitter.com/sseraphini/status/1280276957935083522)

and [https://twitter.com/sseraphini/status/1280274128751276032](https://twitter.com/sseraphini/status/1280274128751276032)

anybody solved this using another approach?

---

<div class="post-metadata">

**Author:** ![thekatertot](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/thekatertot/32/25169_2.png) [@thekatertot](https://discuss.circleci.com/u/thekatertot)\
**Post date:** [July 7, 2020, 10:54pm UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/16 "2020-07-07T22:54:15Z")

</div>

Thanks for posting this. This is a cool approach!

---

<div class="post-metadata">

**Author:** ![stone-z](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@stone-z](https://discuss.circleci.com/u/stone-z)\
**Post date:** [August 28, 2020, 7:55am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/17 "2020-08-28T07:55:45Z")

</div>

> 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](https://ideas.circleci.com/ideas/CCI-I-894)

---

<div class="post-metadata">

**Author:** ![stone-z](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@stone-z](https://discuss.circleci.com/u/stone-z)\
**Post date:** [September 1, 2020, 7:40am UTC](https://discuss.circleci.com/t/is-circle-compare-url-still-a-thing/33366/18 "2020-09-01T07:40:43Z")

</div>

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