New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ENV var for branch name where PR came from #1633

Closed
joshk opened this Issue Nov 18, 2013 · 23 comments

Comments

Projects
None yet
@joshk
Copy link
Member

joshk commented Nov 18, 2013

A customer asked for us to export the branch name where the PR came from as they use it in their tests to clone another repo which uses the same branch name structure.

eg. TRAVIS_PULL_REQUEST_SOURCE_BRANCH_NAME (name is a little long) :)

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Jan 30, 2014

How about TRAVIS_PR_ORIGIN_BRANCH?

@sarahhodne

This comment has been minimized.

Copy link
Contributor

sarahhodne commented Jan 30, 2014

I think the “proper” name of said branch is the “head” branch. As in, the head branch is being merged in to the base branch.

At least, that's the names the GitHub API is using.

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Jan 31, 2014

It makes sense to have as consistent a name as possible, so how about TRAVIS_PR_HEAD_BRANCH? (I find TRAVIS_HEAD_BRANCH somewhat lacking.)

@unn

This comment has been minimized.

Copy link

unn commented Mar 14, 2014

+1

I have had a use case for needing both the branch and the slug of the source of the pr.

I was hoping that TRAVIS_REPO_SLUG did what I want, but it was only the destination of the pr.

@roidrage

This comment has been minimized.

Copy link
Member

roidrage commented May 2, 2014

Additionally, we could make the originating repository available, something like TRAVIS_HEAD_REPO_SLUG.

@nathany

This comment has been minimized.

Copy link

nathany commented May 7, 2014

Does adding an ENV var also make the PR source branch available to notifications %{branch} #2274?

@kayako-utsavhanda

This comment has been minimized.

Copy link

kayako-utsavhanda commented May 29, 2014

+1

This would be beneficial in building projects which include Lib dependency.

Any update on this?

@roidrage roidrage added the bugsquash label Jun 16, 2014

@ghost

This comment has been minimized.

Copy link

ghost commented Feb 9, 2015

For workflows that produce an integration-test artifact when building a pull request, this feature would be super useful to help me choose a reasonable name for the test artifact. Please consider adding this, as the effort seems to small and the benefit large.

@sarahhodne sarahhodne removed the bugsquash label Feb 27, 2015

@bpinto

This comment has been minimized.

Copy link

bpinto commented Sep 28, 2015

I have started testing travis for our organisation builds but I am missing this. Not sure if there is an workaround? But we need this in order to create docker images per PR in order to automatically create staging environments.

@brianguertin

This comment has been minimized.

Copy link

brianguertin commented Sep 28, 2015

@bpinto My workaround for now is:

git fetch --tags
git fetch --unshallow
BRANCH=`git rev-parse --abbrev-ref HEAD`

EDIT: I also use tags to determine build output; the above will also ensure git describe works correctly.

@bpinto

This comment has been minimized.

Copy link

bpinto commented Sep 28, 2015

Thanks @brianguertin

@bpinto

This comment has been minimized.

Copy link

bpinto commented Sep 29, 2015

I couldn't get it to work @brianguertin

The output of git rev-parse --abbrev-ref HEAD was HEAD. =/

@brianguertin

This comment has been minimized.

Copy link

brianguertin commented Sep 29, 2015

@bpinto I don't know what to say, it works flawlessly for me both locally and on Travis CI.

I think if you see HEAD that means you got yourself in a detached HEAD state.

@derekstavis

This comment has been minimized.

Copy link

derekstavis commented Oct 1, 2015

So here we go. I have wrote a bash script workaround which uses GitHub API.

You can check it here: https://gist.github.com/derekstavis/0526ac13cfecb5d6ffe5#file-travis-github-pull-request-integration-sh

This script patches environment variables, allowing you to run tests on source repository/branch every time a PR is created or updated (force pushed).

@fotinakis

This comment has been minimized.

Copy link

fotinakis commented Nov 30, 2015

Hey Travis CI devs—this tiny feature would really help, can anyone take this on or give direction?

For Percy.io CI integration, we rely on knowing the PR's origin branch name so we can do a visual comparison of the branch vs. master—we simply can't integrate fully with Travis CI without this environment variable.

@breerly

This comment has been minimized.

Copy link

breerly commented Mar 3, 2016

I've written a blog post with a workaround for this issue - https://graysonkoonce.com/getting-the-current-branch-name-during-a-pull-request-in-travis-ci/

Also created a issue shown above, #5731

language: go

script:  
  - export PR=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
  - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo `curl -s $PR | jq -r .head.ref`; fi)
  - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH"

The above will create a $BRANCH env var that is the correct value no matter what.

@fotinakis

This comment has been minimized.

Copy link

fotinakis commented Mar 3, 2016

@joshk @BanzaiMan @henrikhodne Hey Travis CI friends, any chance we can get some insider info of if this is on the roadmap?

@bestdan

This comment has been minimized.

Copy link

bestdan commented Mar 7, 2016

+1

2 similar comments
@breerly

This comment has been minimized.

Copy link

breerly commented Mar 8, 2016

+1

@wipatrick

This comment has been minimized.

Copy link

wipatrick commented Mar 10, 2016

+1

@travis-ci travis-ci locked and limited conversation to collaborators Mar 10, 2016

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Mar 10, 2016

We will update this issue when we have something to share. In the meantime, please use the "Subscribe" feature to keep abreast of this.

Thank you.

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Sep 29, 2016

travis-ci/travis-build#848 resolves this issue. The name for this environment variable is currently TRAVIS_PULL_REQUEST_BRANCH. (The PR also adds TRAVIS_PULL_REQUEST_SHA, which points to the HEAD of the PR branch.)

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Sep 29, 2016

This has been deployed. The documentation will be updated shortly. travis-ci/docs-travis-ci-com#742

@BanzaiMan BanzaiMan closed this Sep 29, 2016

@BanzaiMan BanzaiMan self-assigned this Sep 29, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.