Rename Deployment Step

Hi Team,

Need Help With Following Use Case Via REST API Method.

  1. Rename The Step Where Step Name Is “Test A” to Step Name As “Test B” and then points it package feed to external feed rather then “feeds-builtin”. If not possible then how to create new step as “Deploy A Package” and choose custom inline script along with external feed.

Note: I guess re-naming would be easy task as later on I can change the feed type.

PowerShell Working Script

# Define working variables
$OctopusURL = ""
$OctopusAPIKey = ""
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }
$SpaceName = "Default"
$ProjectName = "";
$DeploymentStep = "Deploy Test A"

# Get Space
$Space = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/spaces/all" -Headers $Header) | Where-Object { $_.Name -eq $SpaceName }

# Get Information About Source Project Name
$Projects = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header)
$Project = ($Projects | Where-Object { $_.Name -eq $ProjectName })

# Modify Deployment Settings
if ($null -ne $($Project)) {
    $Project.AutoCreateRelease = $false
    $Project.ReleaseCreationStrategy.ReleaseCreationPackageStepId = ""
    $Project.ReleaseCreationStrategy.ChannelId = $null
    $Project.VersioningStrategy.DonorPackage = $null
    $Project.VersioningStrategy.DonorPackageStepId = $null
    $Project.VersioningStrategy.Template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.NextPatch}"
    $JsonPayload = $Project | ConvertTo-Json

    # Submit Request
    Invoke-RestMethod -Method Put -UseBasicParsing -Uri "$OctopusURL/api/$($Space.Id)/projects/$($Project.id)" -Body $JsonPayload -Headers $Header
}
else {
    Write-Error "Project [$ProjectName] Not Found In $OctopusURL"
}

# Rename Or Remove Deployment Step
$DeploymentProcessURL = ($OctopusURL + ($Project.Links.DeploymentProcess))
$DeploymentProcess = Invoke-RestMethod -Method Get -Uri "$DeploymentProcessURL" -Headers $Header
$IndexOfStep = $DeploymentProcess.Steps.Name.IndexOf($DeploymentStep)
[System.Collections.ArrayList]$Steps = $DeploymentProcess.Steps
if($IndexOfStep -ne -1) {     
     $Steps.RemoveAt($IndexOfStep)
}
else {
      Write-Host "'$DeploymentStep' Does Not Exist In This $($ProjectName)" -ForegroundColor Green
 }
 
$DeploymentProcess.Steps = $Steps
$JsonPayload = ($DeploymentProcess | ConvertTo-Json -Depth 10)

# Submit Request
Write-Host "$OctopusURL/api/$($Space.Id)/projects/$($Project.id)/deploymentprocesses"  
$PayLoadURL = "$OctopusURL/api/$($Space.Id)/projects/$($Project.id)/deploymentprocesses"
Invoke-RestMethod -Method Put -UseBasicParsing -Uri "$PayLoadURL" -Body $JsonPayload -Headers $Header -ContentType "application/json"

@jeremy.miller : See If you can help that will be great as it is kind a high priority requirement.
`
Thanks
Vivek

Hi Vivek,

Thanks for posting your question, and I think I can help here.

It looks like you were mostly on the right track, so I made a few small modifications and added a bit to your script. As always, make sure to backup your data before running any scripts, read through and understand what the script is doing, and test the script against test data prior to running against any production processes.

The script below will go through all steps in a given project to find the old step name (e.g. Deploy Test A), rename it, then update the feed id for the packages under that step.

# Define working variables
$OctopusURL = "https://YOUR_OCTO_URL"
$OctopusAPIKey = "API-####"
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }
$SpaceName = "Default"
$SourceProjectName = "YOUR_PROJECT_NAME"
$OldStepName = "Deploy Test A"
$NewStepName = "Deploy Test B"
$NewFeedId = "Feeds-####"

# Get Space
$Space = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/spaces/all" -Headers $Header) | Where-Object { $_.Name -eq $SpaceName }

# Get Information About Source Project Name
$ProjectInformation = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $SourceProjectName })

# RESET VERSIONING STRATEGY
# Reset deployment settings versioning strategy to default
$DeploymentSettings = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/$($ProjectInformation.Links.DeploymentSettings)" -Headers $Header)
$DeploymentSettings.VersioningStrategy.Template = '#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.NextPatch}'
$DeploymentSettings.VersioningStrategy.DonorPackage = $null
$DeploymentSettings.VersioningStrategy.DonorPackageStepId = $null

# Commit default deployment settings
Invoke-RestMethod -Method Put -Uri "$OctopusURL/$($ProjectInformation.Links.DeploymentSettings)" -Headers $Header -Body ($DeploymentSettings | ConvertTo-Json -Depth 10)

# UPDATE STEP NAME AND PACKAGE FEED
# Get deployment process
$DeploymentProcess= (Invoke-RestMethod -Method Get -Uri "$OctopusURL/$($ProjectInformation.Links.DeploymentProcess)" -Headers $Header)

# Loop through steps and find old step name, update
$stepCounter = 0
foreach ($Steps in $DeploymentProcess.Steps) {
    if ($Steps.Name -ne $OldStepName) {
        $stepCounter ++
    }
    else {
        Write-Host $DeploymentProcess.Steps[$stepCounter].Name
        $DeploymentProcess.Steps[$stepCounter].Name = $NewStepName
        
        # Loop through actions and find old step name, update
        $actionCounter = 0
        foreach($Action in $Steps.Actions){             
            if($Action.Name -ne $OldStepName){
                $actionCounter++
            }
            else {
                $DeploymentProcess.Steps[$stepCounter].Actions[$actionCounter].Name = $NewStepName
            }
            
            # Loop through packages and update feed id
            $packageCounter = 0
            foreach($Package in $Action.Packages){
                $DeploymentProcess.Steps[$stepCounter].Actions[$actionCounter].Packages[$packageCounter].FeedId = $NewFeedId
                $packageCounter++
            }
        }
    }
}    

# Submit request
Invoke-RestMethod -Method Put -Uri "$OctopusURL/$($ProjectInformation.Links.DeploymentProcess)" -Headers $Header -Body ($DeploymentProcess | ConvertTo-Json -Depth 10)

Hopefully that gets you well on the way to what you’re trying to do, but let us know if you have any questions.

Best,
Patrick

Hi @patrick.smergut ,

Thanks for writing the suggestion and the code. However, It works as I expected but it is not able to point external feed name. For Example If I have external feed name called "Test A Feed " then at following snippet it is not working. The External feed is Nuget and I should able to map the package id too. Please help with this

            $packageCounter = 0
            foreach($Package in $Action.Packages){
                $DeploymentProcess.Steps[$stepCounter].Actions[$actionCounter].Packages[$packageCounter].FeedId = $NewFeedId
                $packageCounter++
            }

Hi Vivek,

My apologies for that, as I didn’t include a lookup for the feed name and instead the script uses the FeedId. However, you can get the FeedId quickly for your Nuget feed in the portal by going to Library > Feeds > (your feed), and then the FeedId should show in the URL at the top of your browser.

You can also find these in the API under https://YOUR_OCTO_URL/api/Spaces-1/feeds, where Spaces-1 is your SpaceId, which can also be found under https://YOUR_OCTO_URL/api/Spaces.

I hope that helps and let me know if you need anything else.

Kind regards,
Patrick

Hi @patrick.smergut ,

Thanks for pointing out. Was able to capture the value using below snippets. Still
Not able to sue package id in the step.

Code :

# Get all feeds Is Working 
$feeds = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/feeds/all" -Headers $header)
$NewFeedId = ($feeds | Where-Object {$_.Name -eq $NewFeedId}).Id

# Loop through packages and update feed id
   $packageCounter = 0
            foreach($Package in $Action.Packages){
                $DeploymentProcess.Steps[$stepCounter].Actions[$actionCounter].Packages[$packageCounter].FeedId = $NewFeedId
                $DeploymentProcess.Steps[$stepCounter].Actions[$actionCounter].Packages[$packageCounter].PackageID = $SourceProjectName # It is not working ?
                $packageCounter++
            }

Hi @patrick.smergut ,

Trying to achieve my previous question using below snippet but it is still giving the error:

# Define working variables
$OctopusURL = ""
$OctopusAPIKey = ""
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }
$SpaceName = "Default"
$ProjectName = "Project For Test A";
$DeploymentStep = "Test A"

# Get Space
$Space = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/spaces/all" -Headers $Header) | Where-Object { $_.Name -eq $SpaceName }

# Get Information About Source Project Name
$Projects = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header)
$Project = ($Projects | Where-Object { $_.Name -eq $ProjectName })

$DeploymentProcessURL = ($OctopusURL + ($Project.Links.DeploymentProcess))
$DeploymentProcess = Invoke-RestMethod -Method Get -Uri "$DeploymentProcessURL" -Headers $Header
$DeploymentProcess.Steps | ForEach-Object {
    $_.Actions | ForEach-Object {
        if ($_.ActionType -eq "Octopus.TentaclePackage")
            {
                Write-Output "Setting Feed For Step $($_.Name) To Artifactory"
                $_.Properties["Octopus.Action.Package.FeedId"] = "Feeds-1094"
                $_.Properties["Octopus.Action.Package.PackageId"] = "$ProjectName"
            }
    }
}
$JsonPayload = ($DeploymentProcess | ConvertTo-Json -Depth 10)

Hey Vivek,

I changed the bottom portion and commented out your loop and created a new one.

I believe this is what you were going for. Please let me know if it works for you.

<#$DeploymentProcess.Steps | ForEach-Object {
    $_.Actions | ForEach-Object {
        if ($_.ActionType -eq "Octopus.TentaclePackage")
            {
                Write-Output "Setting Feed For Step $($_.Name) To Artifactory"
                $_.Properties["Octopus.Action.Package.FeedId"] = "Feeds-1094"
                $_.Properties["Octopus.Action.Package.PackageId"] = "$ProjectName"
            }
    }
}
#>


foreach ($step in $DeploymentProcess.Steps){
    foreach ($action in $step.Actions){
        if ($action.Name -eq $DeploymentStep -and $action.ActionType -eq "Octopus.TentaclePackage"){
            Write-Output "Setting Feed For Step $($action.Name) To Artifactory"
            $action.Properties.'Octopus.Action.Package.FeedId' = "Feeds-1094"
            $action.Properties.'Octopus.Action.Package.PackageId' = $ProjectName
        }
    }
}

Best,
Jeremy

Hi @jeremy.miller ,

Thanks for replying back. Well that worked.
I was curious to know, In previous reply from @patrick.smergut ; If you look at the code, I was trying to add the PackageId. However, did not getting the function the array. So I was able to add only Feed but the PackageId. Any help with that snippet will be help full to decide to choose the way of implementation.

# Loop through packages and update feed id
   $packageCounter = 0
            foreach($Package in $Action.Packages){
                $DeploymentProcess.Steps[$stepCounter].Actions[$actionCounter].Packages[$packageCounter].FeedId = $NewFeedId # It is working ?
                $DeploymentProcess.Steps[$stepCounter].Actions[$actionCounter].Packages[$packageCounter].PackageID = $ProjectName  # It is not working ?
                $packageCounter++
            }

Thanks
Vivek

Hi Vivek,

Thanks for posting your follow-up question.

Sorry to ask again if you’ve already provided it, but would you be willing to post the script (without your sensitive details (e.g. URL and API key) where you attempted this? From what I can tell on my end this seems to work, so I’m curious to know what your variables, values, and the remaining context of your script looked like so I can review/test it on my end.

I’m also curious to know what error you might have received in running the script, as that might help as well.

Looking forward to hearing back from you!

Best,
Patrick

Hi @patrick.smergut & @jeremy.miller ,

Thanks for the support so far. I now able to perform the operation as I was expecting.

For Reference I am putting script content with the objective to achieved. In case someone need help, can have it

Use Case :

  1. Create External Nuget Feed Which Should Points To Jfrog Artifactory assuming this is already created at Jfrog Artifactory before this operation at octopus deploy.

  2. Clone the project

  3. Modify the step name as per requirement and update it’s feed type via feed-id and package id.

Working Code:


# Define Working Variables
$OctopusURL = ""
$OctopusAPIKey = ""
$NugetUrl = "" # E.g : http://${ArtifactoryDNS:}8081/artifactory/api/nuget/
$Header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$SpaceName = "Default"
$DownloadAttempts = 5
$DownloadRetryBackOffSeconds = 10
$SourceProjectName = "" # Source Project Name From You Want To Clone
$TeamCityAgentCheckOutDirectory = "" # Get The List Of Directories From Team City Agent CheckOut Directory For Further String Manipulation
$Exclude = "" # Get The List Of Directories From Team City Agent CheckOut Directory For Further String Manipulation While Execluding List Of Folder's. "E.g : Dir1|Dir2|Dir3"
$OldStepName = "" # Provide The Name Of Step Need To Be Rename Post Cloning Of Project
$OctopusProjectNames = "" # Provide The List Octopus Project Names In Advanced Which You Want To Have Post Cloning. E.g : Project-B Which Is Cloned From Project-A

# Error Action Preference
$ErrorActionPreference = "Stop";

# Set To $True To Use The Extended API.
$UseExtendedApi = $False

# Set Username & Password
$FeedUsername = ""
$FeedPassword = ""

# Get Space
$Space = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/spaces/all" -Headers $Header) | Where-Object { $_.Name -eq $SpaceName }

# Get Information About Source Project Name
$ProjectId = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $SourceProjectName }).Id
$ProjectDescription = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $SourceProjectName }).Description
$ProjectGroupId = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $SourceProjectName }).ProjectGroupId
$LifeCycleId = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $SourceProjectName }).LifeCycleId

# Get Job Service Directories
$ServiceDirectories = @()
# $($PreFixDirString) Can Be Like. E.g : DirA.*
((Get-ChildItem -Path $TeamCityAgentCheckOutDirectory -Directory -Filter "$($PreFixDirString)" | Where-Object { $_.Name -notmatch "$Exclude" }).Name) |
ForEach-Object {
	# $($DirStrings) Can Be Like. E.g : DirA.Demo.DirAJobs.Dev
    $($_ -replace ("$($DirString)", "")) | ForEach-Object {                
        if ($($_) -notmatch '[^a-zA-Z0-9]') {                       
            $ServiceDirectories += ($_)            
        }
        if ($($_) -match '[^a-zA-Z0-9]') {            
            #$ServiceDirectories = ($_ -replace [regex]::Escape("."),'_')            
            $ServiceDirectories += ($_ -replace [regex]::Escape("."))            
        }               
    }    
}

foreach ($OctopusProjectName in $OctopusProjectNames) {
    
    # Create Feed

    $FeedName = ($OctopusProjectName -replace ("$($DirString)", ""))    

    $FeedURI = "$($NugetUrl)" + $($OctopusProjectName) + "/"    

    $Body = @{
        Id                          = $null
        FeedType                    = "NuGet"
        DownloadAttempts            = $DownloadAttempts
        DownloadRetryBackoffSeconds = $DownloadRetryBackOffSeconds
        EnhancedMode                = $UseExtendedApi
        Name                        = $FeedName
        FeedUri                     = $FeedURI
    }

    if (-not ([string]::IsNullOrEmpty($FeedUsername))) {
        $Body.Username = $FeedUsername
    }

    if (-not ([string]::IsNullOrEmpty($FeedPassword))) {
        $Body.Password = @{
            HasValue = $True;
            NewValue = $FeedPassword;
        };
    }

    $Validation = ((((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/feeds/all" -Headers $Header).Name) | Select-Object -Skip 2) -match "$FeedName")
    
    if ($null -eq $($Validation)) {
        try {                       
            Write-Host "Not Exists External Feed Name : $($FeedName)" `n

            Write-Host "Creating External Feed Name : $($FeedName) ..." `n
            
            $JsonPayLoad = ($($Body) | ConvertTo-Json -Depth 10)

            Invoke-RestMethod -Method Post -Uri "$OctopusURL/api/$($Space.Id)/feeds" -Body $($JsonPayLoad) -Headers $Header | Out-Null

            Write-Host "Creation of External Feed Name : $($FeedName) Is Now Completed !!!" `n

            # Set Feed
            $Feed = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/feeds/all" -Headers $Header) | Where-Object { $_.Name -eq $FeedName }
        }
        catch {            
            Write-Warning $_.Exception.Message                    
        }        
    }
    else {        
        Write-Host "Already Exists External Feed Name : $($FeedName)" `n
        
        Write-Host "Deleting External Feed Name : $($FeedName)" ... `n                
        
        # Set Feed Before Deletion
        $Feed = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/feeds/all" -Headers $Header) | Where-Object { $_.Name -eq $FeedName }

        # Delete Feed
        Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($space.Id)/feeds/$($Feed.Id)" -Headers $Header | Out-Null        
        
        # Create Feed
        Write-Host "Creating New External Feed Name : $($FeedName) ..." `n
        
        try {                                                            
            # Create Json PayLoad
            $JsonPayLoad = ($($Body) | ConvertTo-Json -Depth 10)
            Invoke-RestMethod -Method Post -Uri "$OctopusURL/api/$($Space.Id)/feeds" -Body $($JsonPayLoad) -Headers $Header | Out-Null            
        }
        catch {            
            Write-Warning $_.Exception.Message                    
        }

        # Set Feed After Creation
        $Feed = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/feeds/all" -Headers $Header) | Where-Object { $_.Name -eq $FeedName }

        Write-Host "Creation Of  External Feed Name : $($FeedName) Is Now Completed !!!" `n
    }

    # Clone Project

    $TargetProjectName = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $OctopusProjectName })
    
    # Create Project Json PayLoad
    $JsonPayLoad = @{
        Name           = $OctopusProjectName
        Description    = $ProjectDescription
        ProjectGroupId = $ProjectGroupId
        LifeCycleId    = $LifeCycleId
    }

    if ($($null) -eq ($($TargetProjectName).Name)) {
        
        try {                                           
            # Create Json PayLoad
            $JsonPayLoad = ($($JsonPayLoad) | ConvertTo-Json -Depth 10)

            # Create Project Using Cloning Method
            Invoke-RestMethod -Method Post -Uri "$OctopusURL/api/$($Space.Id)/projects?clone=$($ProjectId)" -Body $($JsonPayLoad) -Headers $Header | Out-Null

            # Set Project Information After Creation
            $TargetProjectName = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $OctopusProjectName })
        }
        catch {
            Write-Warning $_.Exception.Message
        }
    }
    else {
        Write-Host "Project $($TargetProjectName.Name) Is Already Exists" `n
        
        Write-Host "Deleting & Re-Creating Project $($TargetProjectName.Name) ..." `n

        # Set Project Information Before Deletion
        $TargetProjectName = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $OctopusProjectName })
                
        # Delete Project
        Invoke-RestMethod -Method Delete -Uri "$OctopusURL/api/$($Space.Id)/projects/$($TargetProjectName.Id)" -Headers $Header | Out-Null

        # Create Json PayLoad
        $JsonPayLoad = ($($JsonPayLoad) | ConvertTo-Json -Depth 10)

        # Create Project Using Cloning Method
        Invoke-RestMethod -Method Post -Uri "$OctopusURL/api/$($Space.Id)/projects?clone=$($ProjectId)" -Body $($JsonPayLoad) -Headers $Header | Out-Null

        # Set Project Information After Creation
        $TargetProjectName = ((Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.Id)/projects/all" -Headers $Header) | Where-Object { $_.Name -eq $OctopusProjectName })

        Write-Host "Deleting & Re-Creating Project $($TargetProjectName.Name) Is Completed Now !!!" `n
    }    

    # Update Step Name

    # Set New Step Mame
	# $($DirStrings) Can Be Like. E.g : DirA_Demo_DirAJobs_Dev or dirA_demo_dirAjobs_dev
    foreach ($ServiceDirectory in ($($ServiceDirectories) | Where-Object { $_ -ne "WarrantyAPiCheck" })) {        
        if ($($ServiceDirectory) -eq (($OctopusProjectName -replace ("$($DirStrings)", "")).Trim("dev").Trim("_"))) {
            $NewStepName = "Deploy" + " " + $($ServiceDirectory)
            Write-Host "New Step Name Is : $($NewStepName)"
        }
    }

    # Get Deployment Process
    $DeploymentProcess = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/$($TargetProjectName.Links.DeploymentProcess)" -Headers $Header)

    # Loop Through Steps And Find Old Step Name & Update
    $stepCounter = 0
    foreach ($Steps in $($DeploymentProcess.Steps)) {
        if ($Steps.Name -ne $OldStepName) {
            $stepCounter ++
        }
        else {
            Write-Host $($DeploymentProcess.Steps)[$($stepCounter)].Name
            $($DeploymentProcess.Steps)[$($stepCounter)].Name = $($NewStepName)

            # Loop Through Actions And Find Old Step Name & Update
            $ActionCounter = 0
            foreach ($Action in $Steps.Actions) {             
                if ($Action.Name -ne $OldStepName) {
                    $ActionCounter++
                }
                else {
                    $($DeploymentProcess.Steps)[$($stepCounter)].Actions[$ActionCounter].Name = $($NewStepName)
                }
            
                # Loop Through Packages And Update Feed & Package Id
                $PackageCounter = 0
                foreach ($Package in $Action.Packages) {
                    $($DeploymentProcess.Steps)[$($stepCounter)].Actions[$ActionCounter].Packages[$PackageCounter].FeedId = $($Feed.Id)
                    $($DeploymentProcess.Steps)[$($stepCounter)].Actions[$ActionCounter].Packages[$PackageCounter].PackageId = $($TargetProjectName.Name)
                    $PackageCounter++
                }
            }
        }
    }    

    # Create Json PayLoad
    $JsonPayLoad = ($DeploymentProcess | ConvertTo-Json -Depth 10)

    # Submit Request
    Invoke-RestMethod -Method Put -Uri "$OctopusURL/$($TargetProjectName.Links.DeploymentProcess)" -Headers $Header -Body $($JsonPayLoad) | Out-Null
    
    # Set Versioning Strategy    
    $DeploymentSettings = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/$($TargetProjectName.Links.DeploymentSettings)" -Headers $Header)    
    $DeploymentSettings.VersioningStrategy.DonorPackage = @{DeploymentAction = "$($NewStepName)"; PackageReference = $null; }
    $DeploymentSettings.VersioningStrategy.DonorPackageStepId = "$($NewStepName)"
    $DeploymentSettings.VersioningStrategy.Template = $null
    #$DeploymentSettings.VersioningStrategy.Template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.NextPatch}"
    
    # Create Json PayLoad
    $JsonPayLoad = $DeploymentSettings | ConvertTo-Json -Depth 10

    # Submit Request
    Invoke-RestMethod -Method Put -UseBasicParsing -Uri "$OctopusURL/$($TargetProjectName.Links.DeploymentSettings)" -Headers $Header -Body $($JsonPayLoad) | Out-Null    
    
}

Hi Vivek,

Thanks for getting back to me and I’m glad to hear you got everything working as you were hoping to. Also, thanks very much for posting your final script in case others find it helpful - it’s much appreciated!

Let us know if you need anything else, but otherwise I hope you have a great rest of your week.

Kind regards,
Patrick

Hi @patrick.smergut

Before Closing The Thread, Wanted To How We Can Create Step In Project Which Use “Deploy Package” as a step and pass the “Package Details” and use “inline-Script”.

Note: This is not he plain inline-script. I am talking about if you want to deploy the package on target role but you want to custom inline-script and use it in pre-deployment. Please see if you some thing already in handy, this will solve my complete problems.

Thanks
Vivek

Hi Vivek,

Unfortunately we don’t have a sample script on hand to provide you with, but you should be able to create this by working from the following script in our API documentation examples:

This is for creating a ‘Run a Script’ step, however, if you create a project with a step configured how you’ve described you can export the JSON for that project’s process, then use that to adapt the script to build your own step.

I hope that’s helpful, and let us know if you have any questions.

Best,
Patrick

Hi @patrick.smergut ,

Thanks for providing the input. I will go over with details and will open another post for such request.

Thanks
Vivek

1 Like

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