sh 去Jenkins CI脚本 - golang
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 去Jenkins CI脚本 - golang相关的知识,希望对你有一定的参考价值。
#!/bin/bash
# Go build script that runs cloc, cpd, lint, vet, test and coverage for Jenkins
#
# Outside tools include:
# gocov: go get github.com/axw/gocov
# gocov-xml: go get github.com/t-yuki/gocov-xml
# go2xunit: go get bitbucket.org/tebeka/go2xunit
# jscpd: npm i jscpd -g
# cloc: npm i cloc -g
set -x
# Set up environment
export PATH=$PATH:/var/lib/jenkins/go/bin
export PRJ=`git config --get remote.origin.url | sed 's/^https:\/\///' | sed 's/\.git$//'`
export GODOCPATH=/var/lib/jenkins/go/src
export GOPATH=`pwd`
# Clean directory
git clean -dfx
# Move project into GOPATH
mkdir -p src/$PRJ
ls -1 | grep -v ^src | xargs -I{} mv {} src/$PRJ/
# Copy project to GODOCPATH for documentation hosting
mkdir -p $GODOCPATH/$PRJ
rsync -azu --delete --exclude="vendor" --exclude="Godeps" src/$PRJ/* $GODOCPATH/$PRJ
# LOC reporting (SLOCCount plugin)
cloc --by-file --xml --out=cloc.xml --exclude-dir=vendor,Godeps .
# Copy-paste detection (DRY plugin)
jscpd -e {**/vendor/**,**/Godeps/**,**/*.min.*} -o cpd.xml
# Make distribution directory
mkdir dist
# Run tests (JUnit plugin)
rm -f test.out
echo "mode: set" > coverage.out
for pkg in $(go list $PRJ/...);
do
if [[ $pkg != *"vendor"* ]]; then
echo "testing... $pkg"
go test -v -coverprofile=tmp.out $pkg >> test.out
if [ -f tmp.out ]; then
cat tmp.out | grep -v "mode: set" >> coverage.out
fi
fi
done
rm -f ./tmp.out
cat test.out | go2xunit -output tests.xml
# Generate coverage reports (Cobertura plugin)
gocov convert coverage.out | gocov-xml > cobertura-coverage.xml
# Run lint tools (Compiler warning plugin)
golint $PRJ > lint.txt
# Run vet tools (Compiler warning plugin)
go vet $PRJ > vet.txt
# Build application
go build -o dist/app $PRJ
# Create distro
rsync -az $GOPATH/src/$PRJ/* --exclude="vendor" --exclude="Godeps" --exclude="**/*.go" --exclude=".git*" dist/
# Archive artifact
tar -zcf archive.tar.gz -C dist/ .
以上是关于sh 去Jenkins CI脚本 - golang的主要内容,如果未能解决你的问题,请参考以下文章
Jenkins自动化CI CD流水线之5--pipeline
jenkins构建基于gradle的springboot项目CI采坑(采用jar方式部署)
如何使用 Jenkins 运行 UIAutomation?
Jenkins CI 管道脚本不允许使用方法 groovy.lang.GroovyObject
jenkins上使用shell脚本nohup部署jar服务到remote服务器
CI/CD的实践