Use CreatePipeline com um CLI - AWS SDKExemplos de código

Há mais AWS SDK exemplos disponíveis no GitHub repositório AWS Doc SDK Examples.

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Use CreatePipeline com um CLI

Os exemplos de código a seguir mostram como usar o CreatePipeline.

CLI
AWS CLI

Para criar um pipeline

Este exemplo cria um pipeline AWS CodePipeline usando um JSON arquivo já criado (aqui denominado MySecondPipeline .json) que contém a estrutura do pipeline. Para obter mais informações sobre os requisitos para criar um pipeline, incluindo a estrutura do arquivo, consulte o Guia AWS CodePipeline do usuário.

Comando:

aws codepipeline create-pipeline --cli-input-json file://MySecondPipeline.json

JSONconteúdo de amostra do arquivo:

{ "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-bucket", "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": "MySecondPipeline", "version": 1 } }

Saída:

This command returns the structure of the pipeline.
  • Para API obter detalhes, consulte CreatePipelinena Referência de AWS CLI Comandos.

PowerShell
Ferramentas para PowerShell

Exemplo 1: Esse exemplo cria um novo pipeline com as configurações especificadas.

$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", "amzn-s3-demo-bucket") $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 = "Source" $deployStage.Name = "Beta" $sourceStage.Actions.Add($sourceStageAction) $deployStage.Actions.Add($deployStageAction) $pipeline.ArtifactStore = @{"Location" = "amzn-s3-demo-bucket"; "Type" = "S3"} $pipeline.Name = "CodePipelineDemo" $pipeline.RoleArn = "arn:aws:iam::80398EXAMPLE:role/CodePipelineServiceRole" $pipeline.Stages.Add($sourceStage) $pipeline.Stages.Add($deployStage) $pipeline.Version = 1 New-CPPipeline -Pipeline $pipeline

Saída:

ArtifactStore : Amazon.CodePipeline.Model.ArtifactStore Name : CodePipelineDemo RoleArn : arn:aws:iam::80398EXAMPLE:role/CodePipelineServiceRole Stages : {Source, Beta} Version : 1
  • Para API obter detalhes, consulte CreatePipelineem Referência de AWS Tools for PowerShell cmdlet.