# CIRCLE\_COMPARE\_URL is empty

**URL:** <https://discuss.circleci.com/t/circle-compare-url-is-empty/24549>\
**Category:** Bug Reports\
**Created:** [August 22, 2018, 5:09pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549 "2018-08-22T17:09:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![eps1lon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eps1lon/32/21509_2.png) [@eps1lon](https://discuss.circleci.com/u/eps1lon)\
**Post date:** [August 22, 2018, 5:09pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/1 "2018-08-22T17:09:57Z")

</div>

Over at [https://github.com/mui-org/material-ui](https://github.com/mui-org/material-ui) the CIRCLE\_COMPARE\_URL is only set for jobs that run on the master branch.  
master: [https://circleci.com/gh/mui-org/material-ui/41208](https://circleci.com/gh/mui-org/material-ui/41208)  
pull(from member): [https://circleci.com/gh/mui-org/material-ui/41166](https://circleci.com/gh/mui-org/material-ui/41166)

I wanted to have a list of changed files on the branch CI is running compared to master. Turns out that CircleCI uses hard resets when checking out so `git diff master...` does not work. Parsing the compare url was my next approach but it is empty when needed. I settled on `git rev parse origin/master` but that seems to cause some troubles. Using the compare url would be better and ideal would be to expose just the commit range.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [August 22, 2018, 6:49pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/2 "2018-08-22T18:49:05Z")

</div>

The `checkout` command is optional - if you want to replace it with your own Git command, you can do that.

---

<div class="post-metadata">

**Author:** ![eps1lon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eps1lon/32/21509_2.png) [@eps1lon](https://discuss.circleci.com/u/eps1lon)\
**Post date:** [August 22, 2018, 7:45pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/3 "2018-08-22T19:45:42Z")

</div>

It would be enough to not reset hard to the commit that triggered the build. Do you know why CircleCI does that?

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [August 22, 2018, 7:46pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/4 "2018-08-22T19:46:41Z")

</div>

No idea, sorry. The `checkout` command has always suited my needs, and I’ve had no call to look into alternatives. Would it be complicated to write an alternative? It seems to me it’s just two steps: install the SSH key and do a clone.

Edit: of course, you could use the `checkout` and then do another Git operation on top. You have the full history there, so such a command should be possible.

---

<div class="post-metadata">

**Author:** ![eps1lon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eps1lon/32/21509_2.png) [@eps1lon](https://discuss.circleci.com/u/eps1lon)\
**Post date:** [August 22, 2018, 7:57pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/5 "2018-08-22T19:57:30Z")

</div>

The default checkout command does quite a bit so I’d rather not reduce it to two lines. I could just copy it and remove the hard reset but that seems to hacky.

The diff to master isn’t such a good idea in the first place considering our use case. It includes also files that got change on master during the lifetime of the branch. I basically want to run a code formatter on the files changed in the pull request and see if they conform.

It comes down to finding the commit where the branch was created. Not sure if this is possible. Since TravisCI already has a builtin environment variable I guess it is.

---

<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:** [November 11, 2018, 4:57pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/6 "2018-11-11T16:57:01Z")

</div>

Anybody has fixed this? or is there any workaround?

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [November 11, 2018, 8:14pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/7 "2018-11-11T20:14:57Z")

</div>

> [@sibelius](#):
>
> Anybody has fixed this?

I don’t think there is anything to fix (or it is not clear what you want fixing). Most users (and I include myself here) do not understand the black magic of the checkout command - it just works. If you want to do something non-standard, then install an SSH key and use `git` manually.

---

<div class="post-metadata">

**Author:** ![kariem](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kariem/32/19799_2.png) [@kariem](https://discuss.circleci.com/u/kariem)\
**Post date:** [November 22, 2018, 11:18am UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/8 "2018-11-22T11:18:50Z")

</div>

`CIRCLE_COMPARE_URL` is empty is also the case for me. I am referring to the output in the “Spin up Environment” section:

```
...
Using build environment variables:
  BASH_ENV=/tmp/.bash_env-5bf683e0dc1d530008e33ad3-0-build
  CI=true
  CIRCLECI=true
  CIRCLE_BRANCH=develop
  CIRCLE_BUILD_NUM=72
  ...
  CIRCLE_COMPARE_URL=
  ...
  CIRCLE_WORKING_DIRECTORY=~/project

```

If I understand @eps1lon correctly, they want to use the `CIRCLE_COMPARE_URL`. I also think that @sibelius was referring to this problem and not intended to continue the side discussion around replacing the `checkout` command.

In my specific use case, it would be interesting to see what directories have changed since the last successful build. However, I am not quite sure whether the `CIRCLE_COMPARE_URL` is very helpful in this situation, as it only includes all commits for the current build with no information on whether a previous build was successful.

---

<div class="post-metadata">

**Author:** ![ksteinbeck](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ksteinbeck/32/19946_2.png) [@ksteinbeck](https://discuss.circleci.com/u/ksteinbeck)\
**Post date:** [December 11, 2018, 9:35pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/9 "2018-12-11T21:35:04Z")

</div>

This ENV VAR: CIRCLE\_COMPARE\_URL= is now empty for us as well. We use it for release notes. Thoughts on how to get this ENV VAR back??

---

<div class="post-metadata">

**Author:** ![eps1lon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eps1lon/32/21509_2.png) [@eps1lon](https://discuss.circleci.com/u/eps1lon)\
**Post date:** [February 25, 2019, 10:43am UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/10 "2019-02-25T10:43:40Z")

</div>

There are two issues here: One is that CIRCLE\_COMPARE\_URL is empty for some repos on pull requests.

The other problem is that I can’t use merge base to build the compare url on my own because the default checkout command uses reset --hard instead of simply checking out.

Now I could just go ahead and write my own checkout command. I would hope that the default checkout command was written with intent and that the reset --hard serves some purpose. Without knowing that intent it is dangerous to replace it. IMO you should never remove something if you don’t know its purpose.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [February 25, 2019, 1:36pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/11 "2019-02-25T13:36:47Z")

</div>

This is a known issue internally, Until it gets prioritized above a few other things, we recomend using the conpare-url Orb as a workaround [https://circleci.com/orbs/registry/orb/iynere/compare-url](https://circleci.com/orbs/registry/orb/iynere/compare-url)

Please let me know if this does not meet your needs.

---

<div class="post-metadata">

**Author:** ![eps1lon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eps1lon/32/21509_2.png) [@eps1lon](https://discuss.circleci.com/u/eps1lon)\
**Post date:** [February 26, 2019, 3:33pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/12 "2019-02-26T15:33:19Z")

</div>

Thank you for responding. I didn’t look into the orb yet. However, It’s great to know that this issue is recognized and a official recommendation is given for a workaround.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [February 26, 2019, 3:35pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/13 "2019-02-26T15:35:45Z")

</div>

To be clear, that orb was written by a CircleCI employee, it is just under her namespace instead of CircleCI’s for now.

---

<div class="post-metadata">

**Author:** ![YBadiss](https://avatars.discourse-cdn.com/v4/letter/y/db5fbb/32.png) [@YBadiss](https://discuss.circleci.com/u/YBadiss)\
**Post date:** [March 1, 2019, 11:00am UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/14 "2019-03-01T11:00:06Z")

</div>

Hi drazisil,

I am facing the same issue: CIRCLE\_COMPARE\_URL is empty and I need it to be able to list the files modified in my PR’s commits.  
I tried the orb you mentioned, and I get the following output:

```
checking if pull/537 is a new branch...
----------------------------------------------------------------------------------------------------
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed

100 37 100 37 0 0 787 0 --:--:-- --:--:-- --:--:-- 787
----------------------------------------------------------------------------------------------------
yes, pull/537 is new and 42e7c2f289acf3a3540f5c64c15a541e9dd929a4 is its only commit
finding most recent ancestor commit from any other branch...
----------------------------------------------------------------------------------------------------
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed

100 37 100 37 0 0 1088 0 --:--:-- --:--:-- --:--:-- 1088
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed

100 37 100 37 0 0 1541 0 --:--:-- --:--:-- --:--:-- 1541
Exited with code 1

```

I can’t tell why it’s failing, could you help me out with that?

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [March 1, 2019, 2:31pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/15 "2019-03-01T14:31:20Z")

</div>

Hi @YBadiss, can you open an issue on the Orb repo and we can take a look? [https://github.com/iynere/compare-url-orb/issues](https://github.com/iynere/compare-url-orb/issues)

---

<div class="post-metadata">

**Author:** ![fshot](https://avatars.discourse-cdn.com/v4/letter/f/8dc957/32.png) [@fshot](https://discuss.circleci.com/u/fshot)\
**Post date:** [March 6, 2019, 6:28pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/16 "2019-03-06T18:28:27Z")

</div>

I’d love to see the ‘compare-url’ orb moved to the official CircleCI organization, so that we don’t need to adjust our Org security settings to ‘allow uncertified orbs’.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [March 7, 2019, 2:07pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/17 "2019-03-07T14:07:08Z")

</div>

We are holding off doing that for now since we want to fix `CIRCLE_COMPARE_URL` correctly and moving the workaround Orb to official status may give the indication that we don’t plan to fix it.

---

<div class="post-metadata">

**Author:** ![fshot](https://avatars.discourse-cdn.com/v4/letter/f/8dc957/32.png) [@fshot](https://discuss.circleci.com/u/fshot)\
**Post date:** [March 7, 2019, 3:26pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/18 "2019-03-07T15:26:53Z")

</div>

Thanks, that makes sense. We found an alternate temporary workaround, and will look forward to the proper fix.

---

<div class="post-metadata">

**Author:** ![pz325](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/pz325/32/23375_2.png) [@pz325](https://discuss.circleci.com/u/pz325)\
**Post date:** [March 7, 2019, 4:38pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/19 "2019-03-07T16:38:45Z")

</div>

Hi fashot, do you mind to share your workaround please? We have encountered the same issue as [YBadiss](https://discuss.circleci.com/u/YBadiss) has reported when using compare-url orb

---

<div class="post-metadata">

**Author:** ![pz325](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/pz325/32/23375_2.png) [@pz325](https://discuss.circleci.com/u/pz325)\
**Post date:** [March 7, 2019, 4:56pm UTC](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549/20 "2019-03-07T16:56:24Z")

</div>

I think it’s due to the missing $CIRCLE\_TOKEN

```auto
WARNING: you have not stored a CircleCI API token
if this is a private repository, the next step will fail

```

[Next page](https://discuss.circleci.com/t/circle-compare-url-is-empty/24549.md?page=2)
