Use UpdatePipeline with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use UpdatePipeline with an AWS SDK or CLI

The following code examples show how to use UpdatePipeline.

CLI
AWS CLI

To update the structure of a pipeline

This example uses the update-pipeline command with the --cli-input-json argument. This example uses a pre-defined JSON file (MyFirstPipeline.json) to update the structure of a pipeline. AWS CodePipeline recognizes the pipeline name contained in the JSON file, and then applies any changes from modified fields in the pipeline structure to update the pipeline.

Use the following guidelines when creating the pre-defined JSON file:

If you are working with a pipeline structure retrieved using the get-pipeline command, you must remove the metadata section from the pipeline structure in the JSON file (the "metadata": { } lines and the "created," "pipelineARN," and "updated" fields within).The pipeline name cannot be changed.

Command:

aws codepipeline update-pipeline --cli-input-json file://MyFirstPipeline.json

Sample JSON file contents:

{ "pipeline": { "roleArn": "arn:aws:iam::111111111111:role/AWS-CodePipeline-Service", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "MyApp" } ], "configuration": { "S3Bucket": "awscodepipeline-demo-bucket2", "S3ObjectKey": "aws-codepipeline-s3-aws-codedeploy_linux.zip" }, "runOrder": 1 } ] }, { "name": "Beta", "actions": [ { "inputArtifacts": [ { "name": "MyApp" } ], "name": "CodePipelineDemoFleet", "actionTypeId": { "category": "Deploy", "owner": "AWS", "version": "1", "provider": "CodeDeploy" }, "outputArtifacts": [], "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineDemoFleet" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "codepipeline-us-east-1-11EXAMPLE11" }, "name": "MyFirstPipeline", "version": 1 } }

Output:

{ "pipeline": { "artifactStore": { "location": "codepipeline-us-east-1-11EXAMPLE11", "type": "S3" }, "name": "MyFirstPipeline", "roleArn": "arn:aws:iam::111111111111:role/AWS-CodePipeline-Service", "stages": [ { "actions": [ { "actionTypeId": { "__type": "ActionTypeId", "category": "Source", "owner": "AWS", "provider": "S3", "version": "1" }, "configuration": { "S3Bucket": "awscodepipeline-demo-bucket2", "S3ObjectKey": "aws-codepipeline-s3-aws-codedeploy_linux.zip" }, "inputArtifacts": [], "name": "Source", "outputArtifacts": [ { "name": "MyApp" } ], "runOrder": 1 } ], "name": "Source" }, { "actions": [ { "actionTypeId": { "__type": "ActionTypeId", "category": "Deploy", "owner": "AWS", "provider": "CodeDeploy", "version": "1" }, "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineDemoFleet" }, "inputArtifacts": [ { "name": "MyApp" } ], "name": "CodePipelineDemoFleet", "outputArtifacts": [], "runOrder": 1 } ], "name": "Beta" } ], "version": 3 } }
PowerShell
Tools for PowerShell

Example 1: This example updates the specified existing pipeline with the specified settings.

$pipeline = New-Object Amazon.CodePipeline.Model.PipelineDeclaration $sourceStageAction = New-Object Amazon.CodePipeline.Model.ActionDeclaration $deployStageAction = New-Object Amazon.CodePipeline.Model.ActionDeclaration $sourceStageActionOutputArtifact = New-Object Amazon.CodePipeline.Model.OutputArtifact $sourceStageActionOutputArtifact.Name = "MyApp" $sourceStageAction.ActionTypeId = @{"Category" = "Source"; "Owner" = "AWS"; "Provider" = "S3"; "Version" = 1} $sourceStageAction.Configuration.Add("S3Bucket", "MyBucketName") $sourceStageAction.Configuration.Add("S3ObjectKey", "my-object-key-name.zip") $sourceStageAction.OutputArtifacts.Add($sourceStageActionOutputArtifact) $sourceStageAction.Name = "Source" $deployStageActionInputArtifact = New-Object Amazon.CodePipeline.Model.InputArtifact $deployStageActionInputArtifact.Name = "MyApp" $deployStageAction.ActionTypeId = @{"Category" = "Deploy"; "Owner" = "AWS"; "Provider" = "CodeDeploy"; "Version" = 1} $deployStageAction.Configuration.Add("ApplicationName", "CodePipelineDemoApplication") $deployStageAction.Configuration.Add("DeploymentGroupName", "CodePipelineDemoFleet") $deployStageAction.InputArtifacts.Add($deployStageActionInputArtifact) $deployStageAction.Name = "CodePipelineDemoFleet" $sourceStage = New-Object Amazon.CodePipeline.Model.StageDeclaration $deployStage = New-Object Amazon.CodePipeline.Model.StageDeclaration $sourceStage.Name = "MyInputFiles" $deployStage.Name = "MyTestDeployment" $sourceStage.Actions.Add($sourceStageAction) $deployStage.Actions.Add($deployStageAction) $pipeline.ArtifactStore = @{"Location" = "MyBucketName"; "Type" = "S3"} $pipeline.Name = "CodePipelineDemo" $pipeline.RoleArn = "arn:aws:iam::80398EXAMPLE:role/CodePipelineServiceRole" $pipeline.Stages.Add($sourceStage) $pipeline.Stages.Add($deployStage) $pipeline.Version = 1 Update-CPPipeline -Pipeline $pipeline

Output:

ArtifactStore : Amazon.CodePipeline.Model.ArtifactStore Name : CodePipelineDemo RoleArn : arn:aws:iam::80398EXAMPLE:role/CodePipelineServiceRole Stages : {InputFiles, TestDeployment} Version : 2
  • For API details, see UpdatePipeline in AWS Tools for PowerShell Cmdlet Reference.