1. Generally when you create a pipeline (Refer to Step 2 on this page
   
<https://docs.gocd.org/current/configuration/quick_pipeline_setup.html#step-2-material>[1]),
   you give a value for the Branch field in the Materials page.
   2. Now instead of giving an explicit value there, you can use Parameters
   
<https://docs.gocd.org/current/configuration/admin_use_parameters_in_configuration.html>
   [2].
   3. In the parameters page of your pipeline you can define something like
   "BRANCH_NAME" and set the value as "master" or anything else as per your
   requirement.
   4. After defining a parameter in your pipeline, go back to your
   Materials page and replace the Branch field of the material with the
   parameter name
   like *#{BRANCH_NAME}*.

PS: Parameters (along with templates
<https://docs.gocd.org/current/configuration/pipeline_templates.html>) make
your pipeline definitions more powerful in GoCD.

[1] -
https://docs.gocd.org/current/configuration/quick_pipeline_setup.html#step-2-material
[2] -
https://docs.gocd.org/current/configuration/admin_use_parameters_in_configuration.html

HTH

On Tue, Mar 5, 2019 at 9:13 PM Dmytro Tolkodubov <tlk...@gmail.com> wrote:

> Hi Ashwanth!
> Thank you very much for the quick reply!
> Could you please elaborate on how to proceed with option 1: You can
> extract that branch value as a parameter in the pipeline?
> Completely new to GoCD hance the question may sound quite obvious.
>
> Thanks,
> Dima
>
> вт, 5 мар. 2019 г. в 17:30, Ashwanth Kumar <ashwanth.ku...@gmail.com>:
>
>> I can think of the following two ways to do this:
>>
>>    1. If you're using the "Git" material in your pipeline, you already
>>    know the branch your pipeline is building. You can extract that branch
>>    value as a parameter in the pipeline, so you can use it on the material 
>> and
>>    also as an argument to the script that builds the docker image or even as 
>> a
>>    custom environment variable in the pipeline.
>>    2. Or if you prefer to make your script work as expected outside of
>>    GoCD too, you can try the command as specified on this SO answer
>>    <https://stackoverflow.com/a/12142066/1058334>. I tested that command
>>    locally and it works.
>>
>>
>>
>> On Tue, Mar 5, 2019 at 8:38 PM Dmytro Tolkodubov <tlk...@gmail.com>
>> wrote:
>>
>>> Hi all,
>>> I am have looked trough the list of current env vars supported by the
>>> gocd: https://docs.gocd.org/current/faq/environment_variables.html but
>>> did not find any env var representing the current git branch pipeline has
>>> been run against. Does that env var exist? If it does not, is there any
>>> other option to reference the current git branch? We want to reference the
>>> branch name in the outcome docker image tag.
>>>
>>> Thanks in advance for your answer,
>>>
>>> BR,
>>> Dima
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>>
>> Ashwanth Kumar / ashwanthkumar.in
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 

Ashwanth Kumar / ashwanthkumar.in

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to