Search code examples
jenkinstfsbuild-definition

Cancel Jenkins job if TFS Build Definition that queued it was cancelled


I have a TFS Build Definition which has a Queue Jenkins job step. If I cancel the TFS Build Definition the Jenkins job isn't cancelled. Is there a way to make it cancel?

I'm thinking maybe schedule a step to run if build definition was cancelled which cancels the job using Cancelling Jenkins Job from Command line (CLI)


Solution

  • You can add a "Jenkins stop job" task, using Jenkins API like mentioned here or with POST call like mentioned here.

    Configure this task to run only if you cancel the build:

    enter image description here

    eq(variables['Agent.JobStatus'], 'Canceled')