7
votes

I have a build pipeline on VSTS (aka Azure DevOps, as it is known for now) that runs on an agent pool with 2 build agents (agent A and B), with continuous integration set up. I would like to disable simultaneous execution of this build pipeline on different agents, i.e. if there is a build running on agent A, I do not want a build to start running on agent B until the one on agent A is completed.

I can do this by changing the demands to disqualify all but one of the build agents from running the build (e.g. so that only agent A meets the demand). However, this is undesirable as the build agents are shared with other projects, and sometimes the chosen agent would be quite busy, so I do not want to limit the build agent to any specific machine.

Is there a simple way to do this in VSTS?

2
Why do you not want concurrent builds?James Reed
Because the pipeline needs to update a build variable (through VSTS api), which is used throughout the pipeline. I can probably get around it in other ways, but if I can disable concurrent build in one setting it would be the easiestscharnyw
Did you manage to solve this?Ian Yates
@IanYates No, not really. I ended up configuring a single dedicated build agent for the jobscharnyw
Possible solution: stackoverflow.com/a/49055425axmrnv

2 Answers

1
votes

You can use the 'Batch changes while a build is in progress' settings on the trigger page of the build definitions. Docs here: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml

0
votes

i don't find any clean solution, in this thread(https://developercommunity.visualstudio.com/idea/365730/prevent-parallel-execution-of-the-same-build-defin.html) there is a solution as job in powershell.

because my agent are on linux, i implemented it in python, using the environement variable on the build agent (i think the variables will be the same on windows plateform, or if it not the case you can adapt it with the "env" part of the task. the user token of the connection to te API is hidden in a secret variable.

jobs:
-   job: ParallelRunPrevention
    timeoutInMinutes: 240
    displayName: 'prevent parallel execution of the pipeline'
    steps:
        - task: UsePythonVersion@0
          inputs:
            versionSpec: '3.x'
            addToPath: true
            architecture: 'x64'
        - script: |
            pip install azure-devops
          displayName: 'install dependency'
        - task: PythonScript@0
          displayName: 'wait for execution'
          env:
            TASK_TOKEN_USER: $(user_token)
          inputs:
            scriptSource: 'inline'
            script: |

              from azure.devops.connection import Connection
              from msrest.authentication import BasicAuthentication
              from azure.devops.v6_0.pipelines.pipelines_client import PipelinesClient
              import time
              import os


              token = os.environ["TASK_TOKEN_USER"]
              my_definition_id = int(os.environ["SYSTEM_DEFINITIONID"])
              my_build_id = int(os.environ["BUILD_BUILDID"])
              my_project = os.environ["SYSTEM_TEAMPROJECT"]
              my_organization_url = os.environ["SYSTEM_TASKDEFINITIONSURI"]
              credentials = BasicAuthentication('', token)
              connection = Connection(base_url=my_organization_url, creds=credentials)
              pipeline_c: PipelinesClient = connection.clients_v6_0.get_pipelines_client()
              while not len([run for run in pipeline_c.list_runs(project=my_project, pipeline_id=my_definition_id) if
                            run.state == "inProgress" and run.id <= my_build_id]) == 1:
                  print("not free, build stack:")
                  print([run.id for run in pipeline_c.list_runs(project=my_project, pipeline_id=my_definition_id) if
                        run.state == "inProgress" and run.id <= my_build_id])
                  time.sleep(20)
              print("lets go")