CI_PULL_REQUEST no longer when building a PR

It started to work again for me a few days ago.

Anyway, you can add this script to you build to workaround the problem:

if [ -z "{CI_PULL_REQUEST:-}" ]; then CI_PULL_REQUEST=(curl -X GET -u {GITHUB_TOKEN}:x-oauth-basic 'https://api.github.com/repos/{CIRCLE_PROJECT_USERNAME}/{CIRCLE_PROJECT_REPONAME}/pulls?head={CIRCLE_PROJECT_USERNAME}:{CIRCLE_BRANCH}’ | jq “.[0].url”)
fi

If CI_PULL_REQUEST is not defined or is empty, this script will call the Github API to retrieve the URL of the first PR that has a the current branch as head.
Just make sure to generate a token on Github and to add it as an environment variable on Circle CI. In this example the variable to create is named GITHUB_TOKEN.
Hope it help someone.

1 Like