Jenkins 常用的项目构建工具集成 03 GO
Go项目构建工具
先安装go的开发环境
安装配置
[root@zeyang-nuc-service cicd]# tar zxf go1.16.3.linux-amd64.tar.gz -C /usr/local/
[root@zeyang-nuc-service cicd]# cd /usr/local/go/
[root@zeyang-nuc-service go]# ls
AUTHORS CONTRIBUTORS PATENTS SECURITY.md api doc lib pkg src
CONTRIBUTING.md LICENSE README.md VERSION bin favicon.ico misc robots.txt test
[root@zeyang-nuc-service go]# pwd
/usr/local/go
[root@zeyang-nuc-service go]# vi /etc/profile
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
[root@zeyang-nuc-service go]# source /etc/profile
[root@zeyang-nuc-service go]# go version
go version go1.16.3 linux/amd64
常用命令
- go clean 清空构建
- go build 构建源文件
- go doc 生成godoc文档
- go install 编译并安装指定的代码包
- go fmt 代码格式化
- go get 获取一个包
- go run 运行一个go文件
- go test 运行测试
[root@jenkins-master ~]# cd devops-golang-service-master
[root@jenkins-master devops-golang-service-master]# ls
demo.go Jenkinsfile README.md
[root@jenkins-master devops-golang-service-master]# go build demo.go
[root@jenkins-master devops-golang-service-master]# ls
demo demo.go Jenkinsfile README.md
[root@jenkins-master devops-golang-service-master]# ./demo
Hello World!
[root@jenkins-master devops-golang-service-master]# go run demo.go
Hello World!
Pipeline样例
def buildTools = ["golang": "/usr/local/go"]
pipeline {
agent { label "build" }
options {
skipDefaultCheckout true
}
stages {
stage("GetCode"){
steps{
script{
println("下载代码 --> 分支: ${env.branchName}")
checkout([$class: 'GitSCM', branches: [[name: "${env.branchName}"]],
extensions: [],
userRemoteConfigs: [[credentialsId: '823b86fe-2c1b-466e-b0c3-66ae6991449d',
url: "${env.gitHttpURL}"]]])
}
}
}
stage("Build"){
steps {
script {
sh "${buildTools["golang"]}/bin/go build demo.go"
}
}
}
}
}
目录 返回
首页