Reputation: 1
How to get the resolved value of codepipeline level variable which defaults to #{SourceVariables.CommitId}
?
I have setup a codepipeline having Bitbucket repo as Source and codebuild for deploy stage.
Use case: I want to access the commit id in codebuild. By default it should be the latest commit id of source bitbucket repo, but for rollback purpose, I should be able to manually pass an old/custom commit id if I want.
Implementation: The pipeline has a codepipeline level variable COMMIT_ID_VAR which defaults to #{SourceVariables.CommitId}
.
AppPipeline:
Type: 'AWS::CodePipeline::Pipeline'
Properties:
Name: 'test-pipeline'
PipelineType: V2
Variables:
- Description: Change this variable to deploy a specific commit instead of latest commit.
Name: 'COMMIT_ID_VAR'
DefaultValue: '#{SourceVariables.CommitId}'
I have added COMMIT_ID_VAR as an environment variable in codebuild:
- Name: Deploy
Actions:
- Name: Deploy-Apps
InputArtifacts:
- Name: SourceOutput
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: CodeBuildProjectPreDeployName
EnvironmentVariables: '[{"name":"COMMIT_ID","value":"#{variables.COMMIT_ID_VAR}","type":"PLAINTEXT"}]'
RunOrder: 1
Issue: I am able to get the custom commit id in codebuild when I am manually entering the codepipeline level variable COMMIT_ID_VAR. But for default case, I am getting the string #{SourceVariables.CommitId}
in codebuild instead of the resolved value i.e., the latest commit id.
https://i.sstatic.net/Q5iSBCnZ.png
How can I get the resolved value of pipeline level variable instead of "#{SourceVariables.CommitId}" for the default case?
Upvotes: 0
Views: 120