issue using a parameter to specify a git branch

1,888 views
Skip to first unread message

stev...@gmail.com

unread,
Apr 14, 2014, 6:38:27 PM4/14/14
to go...@googlegroups.com
Hello folks:
 
I am trying to allow Go users to specify a git branch  when they use the  "Trigger with options" feature of GUI, or use the PIPELINE API to launch a pipe.  Unfrotunately my atempts have not yet succeeded.
 
I  created an environmental variable  GIT_BRANCH and put ${GIT_BRANCH} in the "Branch" text box that is on the "Edit Material - Git" page.
When I try to run the pipeline via the GUI, a red failure notice came up in the lower left hand corner of the screen, and when I selected this notice  received a pop up box that read
Modification check failed for material: URL: http://path/to/repository.git, Branch: ${GIT_BRANCH} [Apr-14 14:49:17]
ERROR: fatal: ambiguous argument 'origin/${GIT_BRANCH}': unknown revision or path not in the working tree. ERROR: Use '--' to separate paths from revisions
Except that  the actual  URL different.
 
In the "Basic Settings" page of a pipline  the default  "Label Template" is set to
 
${COUNT}
 
Since an evniomental  variable is used to set to specify a template,  it seemed reasonable to attempt to use an envrionmental  variable to specify a branch.
 
I also tried using ${env.GIT_BRANCH}, ${go.GIT_BRANCH} and $GIT_BRANCH as well, and each time the paramter is not treated as a parameter (not expanded).
 
I removed the attempt to set the branch, and added a job that executed /usr/bin/env, ran the pipeline and in the console ouptut contqained both
 
[go] setting environment variable 'GIT_BRANCH' to value 'develop'
and
GIT_BRANCH=develop
Thus the paramter is being set.
 
I was able to use a parameter to specify a gt branch,  but I assume that a parameter's value is not meant to be overwitten.when a pipeline is started.
 
 
I am using  Ubuntu linux, release 3.11.0-19-generic.
 
Has anybody else been able to use a variable to specify a branch?  If so, were you succesful, and what operating system where you using?
 
Thank you
 
Steven Widom
 
P.S.  I am speaking for myself, not my employer.
 
 

Aravind SV

unread,
Apr 16, 2014, 5:24:05 AM4/16/14
to stev...@gmail.com, go...@googlegroups.com
Hey Steven,

As you found, you can use a parameter to specify a git branch. But, you cannot use an environment variable in the way you mentioned. The environment variable is made available only during runtime, and not during configuration time.

If you want, you can setup a GIT_BRANCH (on any environment variable) to a specific value, and use that in any custom command. However, changing the value of that, doesn't cause the Go agent to checkout the specific branch. The decision of which branch to use is made very early on the Go server side itself. The branch name is used to decide what branch to wait for commits on.

You can potentially run something like a: git reset --hard some-branch, in a task, but I'm not sure I'd recommend doing that.

What exactly are you trying to do, with that variable name for a branch?

Cheers,
Aravind


--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

stev...@gmail.com

unread,
Apr 16, 2014, 12:41:23 PM4/16/14
to go...@googlegroups.com, stev...@gmail.com
Hello Aravind:
 
Thank you for your response.
 
The ultimate goal is to  to make it easy for test to utilize different Git  branches to be run without adding a new pipeline.   It may be that the best solution is to utilize cloning and/or templates.    I was also hoping for a solutin that could be done using REST APIs in case somebody has a low bandwith connection.
 
Steven

Ming Xie

unread,
Jul 31, 2015, 11:54:12 AM7/31/15
to go-cd, stev...@gmail.com
I thought the Git feature branch plugin could help this a bit: https://github.com/ashwanthkumar/gocd-build-github-pull-requests

However, I couldn't figure out how to configure it to do what we want here. Has anyone tried that plug-in?

-Ming

Karolis Blaževičius

unread,
Apr 4, 2017, 6:29:17 AM4/4/17
to go-cd, stev...@gmail.com
Ping!

Karolis Blaževičius

unread,
Apr 4, 2017, 6:29:35 AM4/4/17
to go-cd, stev...@gmail.com
Same problem here!

Ashwanth Kumar

unread,
Apr 5, 2017, 7:20:28 AM4/5/17
to go...@googlegroups.com, stev...@gmail.com
Karolis,

As Aravind pointed out earlier in this thread, you can't use Environment variables for Git Branch expansion, instead you should be using Parameters

Reading through the thread, if you're having fixed number of branches that you want to track progress and make it flow through your CD workflow, consider using templates and multiple pipelines. Instead if you just want to build different branches (aka feature branches) against the repo, consider using the Git Feature Branch plugin or Github Pull Requests plugin if you're based out of Github. The former plugin would build for any branches in a git repo, while the latter builds only Pull Requests sent on Github. 

HTH

PS: I'm the co-author of the above plugins. 

--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Ashwanth Kumar / ashwanthkumar.in

Reply all
Reply to author
Forward
0 new messages