Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to call a manual stage with costum variable API curl call

Daniel Mendes August 8, 2018

Hello how can i call this from a curl call? 

The typical  

curl -X POST --user admin:admin "http://localhost:8085/rest/api/latest/queue/PROJ-PLAN?executeAllStages=true&bamboo.variable.myVariable=newValue" 

does not appear to work when trying to run a manual stage

curl -D- -u USERNAME:PASSWORD -p -H "Content-Type: application/json" -d '?stageB' -f -X PUT "https://COMPANY.atlassian.net/builds/rest/api/latest/queue/${bamboo_buildResultKey}"

I need to mimic with a curl call what we can do in the interface by setting a Variable when running a manual stage

 

1 answer

1 accepted

1 vote
Answer accepted
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Hi @Daniel Mendes,

Please, run the following instead:

# Continue partially done build. Effectively, this method adds build to the build queue, so is not guarantied 
# that build would be executed immediately. Depending on currently executed builds and length of build queue,
# build may be executed when queue would be drained. Additional variables could be passed to this method only
# query parameters (variableName=variableValue). Variables defined in Bamboo as global variables or
# plan variables MUST be prefixed with bamboo.variable ie. bamboo.variable.myVariable=valueForMyVariable. When
# global or plan variables would be passed to this method, will override values valid for previous build
# execution (override).

# replace USERNAME and PASSWORD to authenticate against Bamboo
# replace bamboo.myVar=cURL in case you want to provide build with particular Bamboo variable
# replace http://localhost:8085 with Bamboo's Base URL
# replace PROJ-PLAN-1 with build result you would like to trigger manual stage
# repalce STAGENAME with the name of your stage, if name has space, replace it with plus sign, e.g:
#  Manual Stage, would result into Manual+Stage
curl -k -u USERNAME:PASSWORD \
     -H "Content-type: application/json" \
     -H "Accept: application/json" \
     -d 'bamboo.myVar=cURL' \
     -X PUT 'http://localhost:8085/rest/api/latest/queue/PROJ-PLAN-1?stage=STAGENAME&executeAllStages=true'
    
# consuming variable in build task (i.e Script task)
echo ${bamboo.myVar}

# response
cURL

Reference: https://docs.atlassian.com/atlassian-bamboo/REST/6.6.1/#d2e3903

Kind regards,

Rafael

Daniel Mendes August 9, 2018

Hi,

I tried that already, and it does not set the variable for the next stage.

If i start the pipeline it will set the variable, but continuing the pipeline when it is stopped on a manual stage does not set the Variable and in the metadata it is not there as well.

This works

 curl -k -u ${bambootoken} \
-d "bamboo.MYVAR=somethingsomething" \
-X POST "https://localhost:8085/rest/api/latest/queue/PRJ-P1"

but the goal is to continue a build stage not to trigger the plan so  

 curl -k -u ${bambootoken} \
-H "Content-type: application/json" \
-H "Accept: application/json" \
-d "bamboo.MYVAR=somethingsomething" \
-X PUT "https://localhost:8085/rest/api/latest/queue/PRJ-P1-88?stage=Deploy&executeAllStages=true"

is not setting the variable, it triggers the stage but the variable is not set and echo inside the plan returns the previous value not the one that is passed in the curl call.

rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 10, 2018

Hi @Daniel Mendes,

In order to continue the build, you must specify the build number as mentioned in previous comment, e.g: PROJ-PLAN-1

-X PUT 'http://localhost:8085/rest/api/latest/queue/PROJ-PLAN-1?stage=STAGENAME&executeAllStages=true'

Kind regards,

Rafael

Daniel Mendes August 10, 2018

Hi Rafael I am sorry it was my mistake in writing the command, I tried with the build number the variable  passed in -d  is not taken into account using the PUT method.

Did you test this.... I am on ver 6.5 of Bamboo

The only thing that finally worked was to put it as a url query parameter thank you for pointing me to the documentation, in the end it helped

-X PUT 'http://localhost:8085/rest/api/latest/queue/PROJ-PLAN-1?stage=STAGENAME&executeAllStages=true&bamboo.variable.EXT_URL=http://myexternalurl'

 

Like pBogey likes this
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 10, 2018

Hi @Daniel Mendes,

Thank you for your update.

I am glad it is working for you now. If you also agree, please mark this answer as resolved so others facing the same issue will land to the correct answer / thread.

Kind regards,

Rafael

Like Steffen Opel _Utoolity_ likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events