Stop Bitbucket pipeline using API call - bitbucket

I have pipeline that has been triggered schedule base. I wanted it to stop if some condition has failed so pipeline should be stop. I have check API's i couldn't find a way to stop pipeline itself.

Related

Jenkins Pipeline: Catch Abort from UI and Handle it safely for dockerized agent

I am running a job defined with Jenkins declarative pipeline.
The pipeline uses a docker agent as the worker which is used to run terraform (plan and apply)
When a user clicks "abort" or "cancel" in the Jenkins UI, the pipeline is terminated (SIGTERM) is sent to the Docker process (I think ...).
This results in terraform being shut down uncleanly.
What I would like to do is the following:
If a user clicks abort in the Jenkins UI, catch this before any process is actually terminated
and instead, shut down the pipeline another way (maybe freeze the agent or something safer like send a cancel to the running process in the docker container).
I have tried the following:
try{}catch(err){}, however this aborts the pipeline, terminating the docker agent before actually executing the actions in the catch. So not much use.
a post{} action for the stage, which also just carries out a post action in the event of an ABORT but after the abort.
Question:
Is there a method in Jenkins (preferably using Jenkins declarative pipeline) to handle the ABORT signal before it is actually applied and decide whether to abort or not ?
(Value: If this is possible it would enable me to smoothly manage the abort of Terraform jobs by users, avoiding infrastructure damage.)
Many thanks in advance for any help!

Trouble stopping jenkins pipeline jobs

Trouble aborting pipeline jobs
We recently converted some of our jobs over to pipeline jobs (specifically, multibranch pipeline jobs), and since we did so, stopping builds has become much more problematic.
Back when they were freestyle jobs, the builds would immediately stop when we clicked the red X next to a build.
But when we do that in a pipeline job, often it won't stop. In the console output, we'll get something like this:
Aborted by [USERNAME]
Sending interrupt signal to process
Click here to forcibly terminate running steps
We have to click that link in the third line, and then it often leaves mercurial repositories in a bad state.
Why did stopping builds work fine with freestyle jobs, but not with Pipeline jobs, and is there any way to get them working well with Pipeline jobs?

Make pipeline job wait until previous is built

How to make jenkins pipeline script programmatically wait until previous/last job execution is currently running or succeeded?
There is option to disable concurrent builds, but that is a really bad option that will stack commits.

Jenkins, pipline code to run branch indexing in multibranch pipeline

I've got my Jenkins setup to run multibranch pipeline project where I use API to trigger specific branches in it.
my problem is that it only works if the branch was indexed, otherwise I get 404 from the API.
I have managed to run the branch indexing via the API, but I have no indication of when this task has been completed
by trail and error I have been able to figure out that:
the API call to branch indexing does not return queue ID so I cannot check what its status
the indexing task runs immediately, regardless of the queue and the executes limitation.
I have been unable to run this task from pipeline (other job), trying to run this task results in error
is there any way to tell if the task has completed, and the success value of it?

Bitbucket webhook trigger after pipeline completes successfully

I'd like to trigger a webhook after a pipeline completes successfully, I looked in the trigger list and didn't find any, is there a workaround to trigger webhook manually via pipeliens?
You can use the Build status updated trigger to trigger a webhook based on a pipelines build. However, this will also be triggered by the INPROGRESS or FAILED state, and there is no possibility to specify a pipeline.
If you only want to trigger a webhook from when a specific pipeline completes succesfully, you can do this manually by adding the necessary commands to your bitbucket-pipelines.yaml file.
If you have multiple parallel steps in your pipeline, you should add the webhook trigger in a separate serial step, so it only runs when all parallel steps have completed.

Resources