While using the cdk to create a codepipeline that has a github source action I would like to pass the environment variables down to subsequent steps.
self.source_variables = {
"AUTHOR_DATE": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.author_date),
"BRANCH_NAME": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.branch_name),
"COMMIT_ID": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.commit_id),
# "COMMIT_MESSAGE": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.commit_message),
"COMMITTER_DATE": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.committer_date),
"COMMIT_URL": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.commit_url),
"REPOSITORY_NAME": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.repository_name),
}
However, if the line for commit_message is not commented out then I am met with an error that says the format is wrong: should be [{name, type, value}]
EnvironmentVariables specified in action config does not match expected format, the expected format is JSON array adhering to the following format: [{"name": "string", "type": "string", "value": "string"}]
the issue is not present with any other value.
Create a simple codepipeline with a GithubSourceAction and a codebuild action like:
self.build_init_action = actions.CodeBuildAction(
action_name="initialize",
project=build_project,
input=self.source,
outputs=[],
environment_variables=self.source_variables
)
The deploy command will succeed but the details for the second stage will not work with the commit_message.
No Errors except when in the console.
EnvironmentVariables specified in action config does not match expected format, the expected format is JSON array adhering to the following format: [{"name": "string", "type": "string", "value": "string"}]
This is :bug: Bug Report
It is equally as likely that I am just missing something wildly dumb.
I can provide cf templates at request.
Hey @MisterBianco ,
thanks for opening the issue. When trying your example, I get the following template when I run cdk synth:
EnvironmentVariables: '[{"name":"AUTHOR_DATE","type":"PLAINTEXT","value":"#{Source_GitHub_NS.AuthorDate}"},{"name":"BRANCH_NAME","type":"PLAINTEXT","value":"#{Source_GitHub_NS.BranchName}"},{"name":"COMMIT_ID","type":"PLAINTEXT","value":"#{Source_GitHub_NS.CommitId}"},{"name":"COMMIT_MESSAGE","type":"PLAINTEXT","value":"#{Source_GitHub_NS.CommitMessage}"},{"name":"COMMITTER_DATE","type":"PLAINTEXT","value":"#{Source_GitHub_NS.CommitterDate}"},{"name":"COMMIT_URL","type":"PLAINTEXT","value":"#{Source_GitHub_NS.CommitUrl}"},{"name":"REPOSITORY_NAME","type":"PLAINTEXT","value":"#{Source_GitHub_NS.RepositoryName}"}]'
That seems correct to me... I don't see why COMMIT_MESSAGE would be any different than the other values here.
You said:
The deploy command will succeed but the details for the second stage will not work with the commit_message.
Can you elaborate on that? Do you mean that cdk deploy succeeds with "COMMIT_MESSAGE": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.commit_message), but the CodePipeline fails at runtime? Or something else? If it is the CodePipeline, can you show me a screenshot of the error you get?
Thanks,
Adam
My cdk.out shows
"EnvironmentVariables": "[{\"name\":\"AUTHOR_DATE\",\"type\":\"PLAINTEXT\",\"value\":\"#{SourceVariables.AuthorDate}\"},{\"name\":\"BRANCH_NAME\",\"type\":\"PLAINTEXT\",\"value\":\"#{SourceVariables.BranchName}\"},{\"name\":\"COMMIT_ID\",\"type\":\"PLAINTEXT\",\"value\":\"#{SourceVariables.CommitId}\"},{\"name\":\"COMMIT_MESSAGE\",\"type\":\"PLAINTEXT\",\"value\":\"#{SourceVariables.CommitMessage}\"},{\"name\":\"COMMITTER_DATE\",\"type\":\"PLAINTEXT\",\"value\":\"#{SourceVariables.CommitterDate}\"},{\"name\":\"COMMIT_URL\",\"type\":\"PLAINTEXT\",\"value\":\"#{SourceVariables.CommitUrl}\"},{\"name\":\"REPOSITORY_NAME\",\"type\":\"PLAINTEXT\",\"value\":\"#{SourceVariables.RepositoryName}\"}]"
The deploy functions perfectly, greens across the terminal. The only issue is when I go to CodePipeline and try to click on the details of the build action and it wont enter the build details. The following image is what I get.

Can you show me the commit message that goes out of the source action and into the build action, that causes this?
I would love to, what do I need to do to retrieve that information. I am very new to codepipelines... And the cdk
Just look at the source action that feeds the build action - there should be the commit message there (and a direct link to the commit).
The commit message is:
- Bosun config files
- java onbuilds
- java full vs slim/alpine builds
- Basically everything else
- reverted a setting that forces dockerfile linting on commit
- reasons: it was inhibiting my work. can be readded later.
- removed the version label to decrease effort in maintaining version parity.
- I dont want to force people to update two places... they will forget.
- Everything to do with dockle
- Node image
- No one will use it, java fanbois everywhere
- Nim image
- No one will use it, java fanbois everywhere
- Elixir image
- No one will use it, java fanbois everywhere
- Rust image
- No one will use it, java fanbois everywhere
Changes to be committed:
modified: .editorconfig
modified: CHANGELOG.md
modified: README.md
modified: TODO.md
modified: Taskfile.yml
modified: alpine/Dockerfile
deleted: alpine/README.md
deleted: go/README.md
modified: go/alpine/Dockerfile
new file: go/alpine/onbuild.Dockerfile
modified: go/bosun.yml
modified: go/full/Dockerfile
new file: go/full/onbuild.Dockerfile
modified: java/bosun.yml
modified: java/build/gradle/Dockerfile
new file: java/build/gradle/onbuild.Dockerfile
modified: java/build/maven/Dockerfile
new file: java/build/maven/onbuild.Dockerfile
modified: java/jre/Dockerfile
modified: python/build/Dockerfile
modified: python/python/Dockerfile
I wonder whether there's some character(s) in the message that make CodePipeline choke on it.
Can you try a simple experiment for me? Can you try committing and pushing an empty commit with a very simple error (EDIT: obviously meant commit) message that for sure doesn't contain any special characters? Something like:
$ git commit --allow-empty -m "Test CodePipeline empty commit"
and see if you get the same error in the CodeBuild Action? (Make sure the deployed version of the CodePipeline is the one that has this error, so with the line "COMMIT_MESSAGE": codebuild.BuildEnvironmentVariable(value=self.source_action.variables.commit_message) present).
Thanks,
Adam
It succeeded.
OK. So this is a CodePipeline issue then. I'll get in contact with the team.
Hey @MisterBianco ,
I've talked to the CodePipeline team, and unfortunately I don't have good news 馃槙 . This is a known issue - apparently the escaping for CodePipeline Variables is incorrect for some action configurations, and CodeBuild environment variables are one of those. So basically, right now, the best advice I can give is to just not use the commitMessage variable with conjunction with CodeBuild environment variables.
If you pay for AWS support, you can open an issue about this, but I can't guarantee when it will be fixed from the CodePipeline side.
Sorry I don't have better news for you. I'm resolving this one, please let us know if you need anything else from our side for this problem.
Thanks,
Adam
Most helpful comment
OK. So this is a CodePipeline issue then. I'll get in contact with the team.