Github 代码管道触发器上的AWS代码构建徽章更新

Github 代码管道触发器上的AWS代码构建徽章更新,github,badge,aws-codepipeline,aws-codebuild,Github,Badge,Aws Codepipeline,Aws Codebuild,我已经创建了一个AWS CodeBuild项目,其中包括一个构建标记,当我手动触发构建时,所有工作正常(即,标记已更新)。我现在添加了一个CodePipeline项目,它触发基于GitHub签入的构建。我可以在代码构建项目历史记录中看到它,但是徽章似乎没有得到更新 手动生成-生成失败-徽章已更新 管道生成-生成成功-标记未更新 手动生成-生成成功-徽章已更新 这是故意的吗?我做错什么了吗?我是否需要再拼凑一个Lambda脚本来做这么简单的事情 CodePipeline生成不支持此功能,因为当C

我已经创建了一个AWS CodeBuild项目,其中包括一个构建标记,当我手动触发构建时,所有工作正常(即,标记已更新)。我现在添加了一个CodePipeline项目,它触发基于GitHub签入的构建。我可以在代码构建项目历史记录中看到它,但是徽章似乎没有得到更新

  • 手动生成-生成失败-徽章已更新
  • 管道生成-生成成功-标记未更新
  • 手动生成-生成成功-徽章已更新

  • 这是故意的吗?我做错什么了吗?我是否需要再拼凑一个Lambda脚本来做这么简单的事情

    CodePipeline生成不支持此功能,因为当CodePipeline将源传递给CodeBuild时,它不包含.git目录


    为了对dstrants的回答进行评论,请求URL与项目相关联,而不是与单个构建相关联。请求URL确实需要指定分支(默认为
    master

    我已经编写了一个构建脚本作为解决方法。在buildspec.yml中,我将可执行文件设置为on,然后运行脚本

      build:
        commands:
          - echo Build started on `date`
          - chmod +x aws_scripts/build.sh
          - aws_scripts/build.sh mvn -B package
    
    脚本本身从master pom.xml中提取细节,将标记设置为“挂起”,调用build命令,处理结果

    #!/bin/bash
    
    mkdir badges
    
    # Artifact
    artifact=$( xmllint --xpath "/*[local-name() = 'project']/*[local-name() = 'artifactId']/text()" pom.xml )
    
    # Version
    version=$( xmllint --xpath "/*[local-name() = 'project']/*[local-name() = 'version']/text()" pom.xml )
    version=${version/-/--} # Hyphen escaping required by shields.io
    
    # Update badges pre-build
    echo "https://img.shields.io/badge/Build-In_progress-orange.svg"
    curl -s "https://img.shields.io/badge/Build-In_progress-orange.svg" > badges/build.svg
    
    echo "https://img.shields.io/badge/Version-$version-green.svg"
    curl -s "https://img.shields.io/badge/Version-$version-green.svg" > badges/version.svg
    
    echo "https://img.shields.io/badge/Unit_Tests-Pending-orange.svg"
    curl -s "https://img.shields.io/badge/Unit_Tests-Pending-orange.svg" > badges/unit-test.svg
    
    # Sync with S3
    aws s3 cp badges s3://endeavour-codebuild/badges/${artifact}/ --recursive --acl public-read
    
    # Build
    { #try
        eval $* &&
        buildresult=0
    } || { #catch
        buildresult=1
    }
    
    # Build
    if [ "$buildresult" -gt "0" ] ; then
            badge_status=failing
            badge_colour=red
    else
            badge_status=passing
            badge_colour=green
    fi
    echo "https://img.shields.io/badge/Build-$badge_status-$badge_colour.svg"
    curl -s "https://img.shields.io/badge/Build-$badge_status-$badge_colour.svg" > badges/build.svg
    
    # Unit tests
    failures=$( xmllint --xpath 'string(//testsuite/@failures) + string(//testsuite/@errors)' API/target/surefire-reports/TEST-*.xml )
    
    if [ "$failures" -gt "0" ] ; then
            badge_status=failing
            badge_colour=red
    else
            badge_status=passing
            badge_colour=green
    fi
    
    echo "Generating badge 'https://img.shields.io/badge/Unit_Tests-$badge_status-$badge_colour.svg'"
    curl -s "https://img.shields.io/badge/Unit_Tests-$badge_status-$badge_colour.svg" > badges/unit-test.svg
    
    # Sync with S3
    aws s3 cp badges s3://endeavour-codebuild/badges/${artifact}/ --recursive --acl public-read
    
    exit ${buildresult}
    
    我创建了这个回购协议:


    只需几个步骤,就可以轻松获得CodeBuild和CodePipeline的构建标志。这些徽章是由运行时间很短的Lambda函数创建的(小于200ms,192MB)。

    很抱歉,我仍然不懂。单个构建与项目相关联(正如历史记录中显示的所有3个)。它们正确地显示了每个生成的状态。为什么徽章不直接与构建状态关联?这不是重点吗?徽章为您提供了项目中特定分支的最新非代码管道构建的状态。代码管道构建没有反映在徽章中是毫无意义的……一年后,情况仍然如此。