CIRCLE_COMPARE_URL is empty

Over at 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
pull(from member): 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.

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

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 https://circleci.com/orbs/registry/orb/iynere/compare-url

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

2 Likes

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.

2 Likes

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? https://github.com/iynere/compare-url-orb/issues

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