Probem to update deploymentprocess using API Rest

Hi

How can i update the below request ?
Url -https://octopus.abc.com/xyz_4367/api/deploymentprocesses/deploymentprocess-Projects-201

Error Response-
{
“ErrorMessage”: “There was a problem with your request.”,
“Errors”: [
“Changes to this deployment process could not be saved, because another user has made changes to the deployment process between when you started editing and when you saved your changes. Please reload or open a new tab to make your changes.”
],
“ParsedHelpLinks”:
}

Similar type of post has exist but i cant find the proper resolution here.

HI Abhinay,

Thanks for getting in touch. That error often occurs if the script is modifying a part of a step without including all required fields. The best practice when changing steps in this way is:

  1. Do a GET on your template deployment process and assign that value to a variable
  2. Modify the values of that variable according to the needs of your new projects
  3. PUT the modified template on your new project.

The below sample script amends the role on a specific step. Hopefully, it will help provide a starting point for you. You can find other script samples here:

# You can this dll from your Octopus Server/Tentacle installation directory or from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll' 

$apikey = '<API KEY>' # Get this from your profile
$octopusURI = 'http://localhost' # Your server address

$projectId = "Projects-1" # Get this from /api/projects
$stepName = "Run a script test" # The name of the step
$role = "demo-role" # The machine role to run this step on

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$project = $repository.Projects.Get($projectId)
$process = $repository.DeploymentProcesses.Get($project.DeploymentProcessId)

$step = $process.Steps | Where-Object Name -Match $stepName 
$step.Properties.'Octopus.Action.TargetRoles' = $roleName

$repository.DeploymentProcesses.Modify($process)

Please let me know if this helps or if there is any further advice I can offer.

Best regards,
Paul

Thanks Paul.

I am able to save the template now using same API as have to pass version number field every time correctly in order to save template.

Hi Abhinay,

Glad you’ve got it working. Feel free to reach out if you have any further issues. :slight_smile:

Best regards,
Paul

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.