Over at the CIRCLE_COMPARE_URL is only set for jobs that run on the master branch.
pull(from member):

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.

1 Like

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

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

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.

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.

1 Like

Anybody has fixed this? or is there any workaround?

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.

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:

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.

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

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.

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

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


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.

1 Like

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


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?

Hi @YBadiss, can you open an issue on the Orb repo and we can take a look?

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

1 Like

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.

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

1 Like

Hi fashot, do you mind to share your workaround please? We have encountered the same issue as YBadiss has reported when using compare-url orb

I think it’s due to the missing $CIRCLE_TOKEN

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