gpt4 book ai didi

aws-codepipeline - AWS CodeBuild - 操作配置中指定的 EnvironmentVariables 与预期格式不匹配

转载 作者:行者123 更新时间:2023-12-03 16:49:16 54 4
gpt4 key购买 nike

我正在尝试向使用 AWS Codebuild 的 Pipeline 操作添加环境变量。但是,无论我添加什么,如果我选择一种 Secret Manager,该步骤都会失败并显示以下错误:

Invalid action configuration

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"}]


这是我在 UI 中输入的内容:
enter image description here
CodePipeline 生成的 JSON 如下所示:
[{"name":"SERVICE_CREDS","value":"my-secret:service_creds","type":"SECRETS_MANAGER"}]
这里发生了什么??我不知道我最后可能会做错什么。我正在他们提供的框中输入文本。 Pipelines 从它们的输入框中生成的 JSON 在我看来是有效的。所以,我不知道为什么说环境变量与预期的格式不匹配!

最佳答案

如果有人在搜索错误后访问此页面:

EnvironmentVariables specified in action config does not match expected format, the expected format is JSON array adhering to the following format



当您的 CodePipeline 将环境变量“#{SourceVariables.CommitMessage}”从 Source 操作提供给 CodeBuild 操作时,这是一个反复出现的问题,并且如果 CommitMessage 包含引号或多行,则该操作将因内部 json 而失败解析器失败。

注意:CodeCommit 始终添加一个“\n”,因此 CodeCommit 始终会出现此问题。对于 GitHub,只有在使用扩展提交消息时才会发生。

现在要在不丢失“COMMIT_MESSAGE”环境变量的情况下解决此问题,请按照以下步骤操作:

解决方法:
  • 从 CodeBuild 操作的 CodePipeline 配置中删除“COMMIT_MESSAGE”环境变量。
  • 确保您的 CodeBuild 项目的服务角色有权在管道上执行“ListPipelineExecutions”。
  • 在 Buildspec 'Install' 阶段添加以下内容以安装 'jq' 实用程序 [1]:
    - apt-get install jq
  • 在需要获取提交消息的 Buildspec 中添加以下内容(请更新管道的名称):
    - COMMIT_MESSAGE=$(aws codepipeline list-pipeline-executions  --pipeline-name <Pipeline_Name> --max-items 1 | jq -r '.pipelineExecutionSummaries[0].sourceRevisions[0].revisionSummary')
    - export COMMIT_MESSAGE
    - echo $COMMIT_MESSAGE # debug command only
    - printenv # debug command only

  • 使用此方法,我们使用“list-pipeline-executions”[2] AWS CLI 调用来检索最近的管道执行并解析来自此执行的提交消息。 'COMMIT_MESSAGE' 变量将包含带有任何引号或换行符的完整提交消息。

    引用:

    [1] jq - https://stedolan.github.io/jq/

    [2] 列表管道执行 - https://docs.aws.amazon.com/cli/latest/reference/codepipeline/list-pipeline-executions.html

    关于aws-codepipeline - AWS CodeBuild - 操作配置中指定的 EnvironmentVariables 与预期格式不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61163037/

    54 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com