7

This seems so trivial, I am almost shy to ask... Depending on certain conditions, which I am able to check by looking at Bamboo variables, I sometimes want to just stop the execution of a build and/or it's deploy. The possibility to conditionally execute steps seems very limited in Bamboo, and I am having trouble solving this. I found a workaround, which is running a script that exits with an error, like a powershell script simple as this

exit 1

But that obviously causes the build to appear as failed, which really isn't what I want. I just want to prevent a deploy in certain conditions.

Does anyone know an elegant way to accomplish a full stop in a Bamboo plan?

Culme
  • 181
  • 1
  • 4
  • 1
    What about exit 0 ? – Tensibai Jun 01 '18 at 14:00
  • @Tensibai - exit 0 will make Bamboo continue executing the following steps in the plan, since exit 0 basically means "I'm done and things went fine". I need it to stop executing. – Culme Jun 01 '18 at 14:32
  • Misread it as stopping the script in middle vs stopping the plan. Not using bamboo so I can't tell. – Tensibai Jun 01 '18 at 14:34
  • You can try setting a Bamboo variable and introduce a conditional within each stage/task to check if it should run the desired code or not. Not an elegant way to do it but it should be doable. – kaizenCoder Jun 03 '18 at 09:25
  • 1
    @kaizenCoder Thanks. But there are several task types that do not contain scripting, and in those task types - how would one introduce the conditional check? – Culme Jun 04 '18 at 06:45
  • @Culme Did you create an issue at bamboo? – 030 Dec 20 '19 at 09:04
  • Hey @030, it's been a while, and to be honest I can't remember whether or not I did.I would guess I did, but got no good reply - but that IS a guess.

    I would still need the feature though, and noticing that the question has been closed made me surprised and disappointed. Would you know how to revive it again? (Seing as you appear to be a mod, from your little diamond mark by your name.)

    – Culme Dec 23 '19 at 11:49
  • Thanks for your reply. I will reopen it. Could you create an issue in the issue tracker of BamBoo and post an answer to this Q&A to create more awareness? – 030 Dec 23 '19 at 11:50
  • 1
    (On a side note: I did try to open an issue with Atlassian on this today. So I go to Bamboo forum, create feature request - system says feature requests need to be input from another system, I go to the other system, choose Bamboo as product, and the other system says I must use the Bamboo forum to submit a feature request.uuuhm. .... but.... I would love to start rambling about this, but hopefully the facts ramble by themselves. – Culme Dec 23 '19 at 12:19

2 Answers2

1

You can manually stop a build in progress. From Stopping an active build:

To stop an active plan build:

  1. Click Dashboard and then the All Plans tab.
  2. Click the 'Stop' icon next to the active plan you want to stop.

It also appears possible to stop the build/deploy programmatically, using the REST API, more specifically making a DELETE request to the appropriate url:

/queue/{projectKey}-{buildKey}-{buildNumber : ([0-9]+)}?stage&executeAllStages ... DELETE Stop build execution.

available response representations:

401 Returned when user does not have sufficient rights to view or execute build for specified plan

204 On success (success is also when build was already completed - so nothing to stop)

404 Returned when specified job does not exist

Dan Cornilescu
  • 6,780
  • 2
  • 21
  • 45
1

I know that is not the clean solution everybody looks for and is a nasty workaround, but what worked for me was to squash all my deployment logic into a single Script Task (shell script) and then put the necessary conditions there, such as:

if [ <put condition for terminate here> ] ; then 
   exit 0
fi 
<Continue with other execution logic>

In that way, you can exit with 0 (thus build shows as successful) , but of course that prevents you from reusing all of the out-of-the-box Bamboo Task types that are readily available and questions the benefits of using the bamboo framework as a wrapper.