我创建了一个包含构建徽章的AWS CodeBuild项目,当我手动触发构建时,一切正常(即徽章已更新)。我现在添加了一个CodePipeline项目,该项目基于GitHub签入触发该构建。我可以在CodeBuild项目历史中看到它,但徽章似乎没有更新?
答案 0 :(得分:2)
我已经编写了一个构建脚本作为解决方法。在buildspec.yml中,我设置了可执行文件,然后运行脚本..
build:
commands:
- echo Build started on `date`
- chmod +x aws_scripts/build.sh
- aws_scripts/build.sh mvn -B package
脚本本身从主pom.xml中提取详细信息,将标记设置为“pending”,调用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}
答案 1 :(得分:0)
CodePipeline版本不支持此功能,因为当CodePipeline将源传递给CodeBuild时,它不包含.git目录。
要评论dstrants的答案,请求URL与项目相关联,而不是与单个构建相关联。请求URL确实需要指定分支(但默认为master
)
答案 2 :(得分:0)
我已经创建了这个仓库:https://github.com/unfor19/aws-build-badges
仅需几个步骤,您就可以轻松拥有CodeBuild和CodePipeline的构建标志。徽章是由Lambda函数创建的,这些函数运行时间非常短(不到200ms,192MB)。