Jenkins部署Golang
编译环境:
1、安装go语言
2、优化测试
部署环境:
1、部署
编译环境(Jenkins)
1、安装golang语言
# 下载Golang
wget https://golang.google.cn/dl/go1.16.3.linux-amd64.tar.gz
# 安装
[root@jenkins opt]# tar -xf go1.16.3.linux-amd64.tar.gz -C /usr/local/
# 添加环境变量
[root@jenkins go]# vim /etc/profile
export GO_HOME=/usr/local/go
export GO_ROOT=/usr/local/go
export GO_PATH=/opt/go
export GOPROXY=https://mirrors.aliyun.com/goproxy/
PATH=$PATH:$GO_HOME:$GO_ROOT:$GO_PATH:$GO_HOME/bin
export PATH
[root@jenkins go]# source /etc/profile
[root@jenkins go]# printenv | grep GO
GO_PATH=/opt/go
GOPROXY=https://mirrors.aliyun.com/goproxy/
GO_HOME=/usr/local/go
GO_ROOT=/usr/local/go
2、测试
[root@jenkins go]# mkdir /opt/go
[root@jenkins go]# cd /opt/go
[root@jenkins go]# go mod init jenkins-go
[root@jenkins go]# go get -u github.com/gin-gonic/gin
[root@jenkins go]# vim main.go
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run("0.0.0.0:8888") // listen and serve on 0.0.0.0:8080
}
[root@jenkins go]# go run main.go
[root@jenkins go]# curl http://192.168.12.90:8888/ping
部署环境(web)
1、运行构建的二进制文件