How to Update Template Version In a pipeline using an API
Let’s say you have a usecase. If you have an account-level pipeline template with version V1.0.0 and a pipeline located under a project is referencing this template and version V1.0.0. Now If you bump up the template version to V1.0.1, Then is there a way to upgrade the pipeline version to V1.0.1 using in-line codes or API calls rather than manually changing the version via the “change template” option?
-
Whenever you change the template version, make sure to make that new version a stable version, so Harness will always use the stable version option, which will be used at the pipeline level and will refer to the latest version.
-
What if your scenario is not allowed to mark the template pipeline version as stable before giving it a full test? That means when you trying to bump up the pipeline version and the version has not been stable yet. So is there a way to do it using inline code or API calls?
- Yes, You can achieve the same using API: Harness API docs
curl -i -X PUT \
'https://app.harness.io/gateway/pipeline/api/pipelines/v2/{pipelineIdentifier}?accountIdentifier=string&orgIdentifier=string&projectIdentifier=string&branch=string&repoIdentifier=string&rootFolder=string&filePath=string&commitMsg=string&lastObjectId=string&resolvedConflictCommitId=string&baseBranch=string&connectorRef=string' \
-H 'Content-Type: application/yaml' \
-H 'If-Match: string' \
-H 'x-api-key: YOUR_API_KEY_HERE' \
-d 'pipeline:
name: Sample Pipeline
identifier: Sample_Pipeline
allowStageExecutions: false
projectIdentifier: Temp
orgIdentifier: default
tags: {}
stages:
- stage:
name: Sample Stage
identifier: Sample_Stage
description: ""
type: Approval
spec:
execution:
steps:
- step:
name: Approval Step
identifier: Approval_Step
type: HarnessApproval
timeout: 1d
spec:
approvalMessage: |-
Please review the following information
and approve the pipeline progression
includePipelineExecutionHistory: true
approvers:
minimumCount: 1
disallowPipelineExecutor: false
userGroups: <+input>
approverInputs: []
- step:
type: ShellScript
name: ShellScript Step
identifier: ShellScript_Step
spec:
shell: Bash
onDelegate: true
source:
type: Inline
spec:
script: <+input>
environmentVariables: []
outputVariables: []
executionTarget: {}
timeout: 10m
tags: {}
- stage:
name: Sample Deploy Stage
identifier: Sample_Deploy_Stage
description: ""
type: Deployment
spec:
serviceConfig:
serviceRef: <+input>
serviceDefinition:
spec:
variables: []
type: Kubernetes
infrastructure:
environmentRef: <+input>
infrastructureDefinition:
type: KubernetesDirect
spec:
connectorRef: <+input>
namespace: <+input>
releaseName: release-<+INFRA_KEY>
allowSimultaneousDeployments: false
execution:
steps:
- step:
name: Rollout Deployment
identifier: rolloutDeployment
type: K8sRollingDeploy
timeout: 10m
spec:
skipDryRun: false
rollbackSteps:
- step:
name: Rollback Rollout Deployment
identifier: rollbackRolloutDeployment
type: K8sRollingRollback
timeout: 10m
spec: {}
tags: {}
failureStrategies:
- onFailure:
errors:
- AllErrors
action:
type: StageRollback
'
-
In the API, you can pass the yaml details, like the version label, which you need to update.
-
This is how you can update Template Version In a pipeline using an API