I'm looking for a way to get a git branch name to use in a script. The head_name
gives me the name of the branch I'm looking for, but I'm unsure how to pass that parameter into a task.
Asked
Active
Viewed 1,097 times
0

Matt Westlake
- 3,499
- 7
- 39
- 80
1 Answers
0
You don't have direct access to the metadata from the get
container.
The git
resource performs a git clone
into the container, so you have access to the data. If your task image has the git
CLI, I would just run git branch --show-current
(from https://stackoverflow.com/a/6245587/4462517).
If your task image does not have git and you can't/don't want to install it, you could add a task like this before your current task:
- task: get-git-branch
config:
platform: linux
image_resource:
type: registry-image
source:
repository: concourse/git-resource
inputs:
- name: source # or whatever your git resource is named
outputs:
- name: branch-info
run:
path: bash
args:
- -c
- |
cd source
git branch --show-current > ../branch-info/current-branch
From there, you could add the branch-info
output as an input to your task, and read the contents of branch-info/current-branch
to use it.

Josh Ghiloni
- 1,260
- 8
- 19