Is there a way to specify a revision number to update to when a build is started from bamboo?
Asked by J. Nicolas Schrading:

I need a way to specify a specific SVN revision number to update the working copy to when a build on bamboo starts. Currently it defaults to the HEAD revision but I do not want it to use that in this case.

I am trying to run in-depth regression tests, using a separate build machine, on the latest succesful build artifacts from a different build machine. If it uses the HEAD revision, there is the possibility that another build from the other machine has started (thus updating the repository), and placing the artifacts this build is using out of synch with the repository it is using (which contains the regression tests)


Answers:
author: Peter Kahn
body: I found another way. It's not as elegant as I'd like, but it works. Accessing the runParametrisedManualBuild.action directly via post and passing in the items.

Example:

```
curl -X POST  http://{bambooBaseURL}/ajax/runParametrisedManualBuild.action?os_authType=basic&amp;planKey=MYCHANGSETBUILD&amp;customRevision=63781
```

<br />

<br />

<br />


author: PiotrA
body: Hello Nicolas,

Regarding your question: I don't think so. At least not out of the box.

If I understand correctly you would like to run a manual build, but using a custom revision (for example r1234) instead of the revision detected by Bamboo (let's assume Bamboo detects r2345). Thing is, that Bamboo's "Source Checkout Task" is using the revision detected by Bamboo (so it would be r2345 in our case) - that revision is also read-only accessible via Bamboo Variable "bamboo.repository.revision.number", but changing it actually doesn't impact the "Source Checkout Task" logic - it would still use internally detected "r2345".

However, if you would get rid of "Source Checkout Task" and instead used own "Script Task" to retrieve SVN sources, you could probably go with something like:

targetRevision=${bamboo.repository.revision.number}

customRevision=${bamboo.my.plan.variable.custom.revision} \<-- set this variable as Plan Variable in Plan Configuration

if (customRevision is not empty) then targetRevision=$customRevision

svn co repoUrl -r $targetRevision

But that would leave you without all the 'goodness' from Bamboo like authenticating to repoUrl and other things. So I'm not sure if that's the feasible solution at all.

What do you think about that? Maybe your use-case is a little bit different?

comments: author: J. Nicolas Schrading
body: Hmm, yeah this seems to work. We just need to figure out how to use a script that passes the revision number we want (determined using python) to set that custom variable, while retaining our ability to keep this build running continuously unless it breaks. Using our script right now, we can get an initial build going, using a custom svn revision number, and have it pass, but we can't start another one for some reason. Another queue at the end of the build, using the REST API queue functionality, gives a http 400 error (bad request, or something like that) so I guess you can't queue while it's running. And if we use Bamboo's built in functionality to start itself, then we can't use the REST API to queue it and start it, thus eliminating our ability to pass in the custom variable (which changes, it isn't a constant revision number).

EDIT: I suppose we could make a script that gets the custom revision number, passes it to the batch file that updates the SVN, and then go from there.


author: PiotrA
body: regarding "400 error when issuing next queuing via REST" - can I ask you if you had set up 'concurrent builds' in your Bamboo instance? <https://confluence.atlassian.com/display/BAMBOO/Configuring+concurrent+builds> - I'm wondering if the 400 error is thrown because you're hiting the 'concurrent' limit for that particular plan... Can you check it?


author: Przemek Bruski
body: What do you mean by "build machine"? Are these Bamboo agents?

comments: author: J. Nicolas Schrading
body: Yeah, different plans using different agents on separate computers.

As an alternate route to doing this, I've tried using the REST API to manually queue a build and pass in a custom svn revision number as a variable through a python script like

```
encoded_query_args = urllib.urlencode({'Basic username' : username, 'password' : password})urllib2.urlopen('http://.../rest/api/latest/queue/{PLANKEY}-{BUIILDKEY}?os_authType=basic&amp;custom.svn.revision.number=10', encoded_query_args)
```

```

```

With {PLANKEY} and {BUILDKEY} replaced with our actual plan and build keys. I've also removed the encoded data as an argument and tried a few other things to get it to work but I either get 401: Unauthorized errors or 405: Method Not Allowed errors. The username and password passed in are correct and can manually kick off a build through bamboo online.


author: J. Nicolas Schrading
body: Well, I've got the authorization working now. I had to make some changes to the above python script. However, passing in bamboo.variable.repository.revision.number=x or bamboo.variable.custom.svn.revision.number=x does not actually change the revision number it updates from. It still uses the HEAD revision. Any solution?


Tags: revision

test