Search code examples
restazure-devopsazure-pipelines-release-pipelinerelease-management

How to create/update environment in release definition pipeline?


I am trying to dynamically create environments with a set of specific predefined tasks and steps. Anyone ever got this working well enough to post some sample code, or a guide?

I can't add an environment, or tasks to an existing one. I keep getting an error BadRequest, but I don't know what am I doing wrong in the JSON payload.

I can get the existing definition, I can do simple things like update the name of the release definition, comments and description when I update, but once I touch the environments it all breaks.

I am using the online URIs - https://vsrm.dev.azure.com/{acct}/{proj}/_apis/release/definitions?api-version=5.1

Is there any way to get more information on what's wrong with my payload, what's bare minimum, or required?


Solution

  • If you mean create/update environment for the specific release definition, then you can try the following steps:

    1. Get that release definition response and convert the response to JSON body: GET https://vsrm.dev.azure.com/{organization}/{Project}/_apis/release/definitions/{definition ID}?api-version=5.1
    2. Add (insert) a new environment (or update the existing one) to that JSON body. You can copy from the existing environment block, then change the parameters accordingly. For example: Add a new environment with "id":0, set a new name, the ranks of release pipeline stages need to be consecutive natural numbers, for example, the rank in previous stage is "2", then it should be "3" here. Keep others same as previous one
    3. Update the release definition by calling the REST API with the updated JSON body: PUT https://vsrm.dev.azure.com/{organization}/{Project}/_apis/release/definitions?api-version=5.1

    You can reference the below screenshot for details: enter image description here