[root@infra2-test-k8s /]# cd /usr/local/ [root@infra2-test-k8s local]# wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz [root@infra2-test-k8s local]# tar -xzvf go1.14.4.linux-amd64.tar.gz
[root@infra2-test-k8s local]# cd / [root@infra2-test-k8s /]# mkdir go
[root@infra2-test-k8s /]# vim /etc/profile # 添加如下內容: export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin export GOPATH=/go export GO111MODULE=auto export GOPROXY=https://goproxy.cn,direct # 使配置文件生效 [root@infra2-test-k8s /]# source /etc/profile # 校驗 [root@infra2-test-k8s /]# go version go version go1.14.4 linux/amd64 [root@infra2-test-k8s /]# go env
在插件管理
的可選插件
中搜索Go
而後點擊直接安裝,安裝完畢以後須要重啓jenkins。
linux
系統管理>全局工具配置>Go>Go安裝
去掉自動安裝
的勾選,而後別名:go1.14.4
,安裝目錄:/usr/local/go
golang
若是出現如下問題:docker
go: command not found
解決辦法:apache
[root@infra2-test-k8s bin]# ln -s /usr/local/go/bin/go /usr/bin/
還不行的話則嘗試將環境變量配置到jenkins中:vim
GOROOT=/usr/local/go PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/jdk1.8.0_231/bin:/opt/apache-maven-3.6.3/bin:/usr/local/go/bin GOPATH=/go GO111MODULE=on GOPROXY=https://goproxy.cn 路徑:系統管理>系統配置>環境變量
Dockerfilecentos
FROM docker.io/centos:7 ENV PROJECT_DIR=/opt/docker ENV TZ=Asia/Shanghai WORKDIR $PROJECT_DIR COPY src/dataservice/dataservice $PROJECT_DIR/goapp COPY src/dataservice/ipipfree.ipdb $PROJECT_DIR/ipipfree.ipdb COPY src/dataservice/ds.cnf $PROJECT_DIR/ds.cnf COPY src/dataservice/start.sh $PROJECT_DIR/start.sh RUN mkdir /opt/logs RUN chown -R daemon:daemon $PROJECT_DIR RUN chown -R daemon:daemon /opt/logs EXPOSE 8080 USER daemon ENTRYPOINT ["sh", "/opt/docker/start.sh", "test"]
start.sh:bash
#!/bin/bash if [[ $1 == 'prod' ]] then sed -i "s/env=.*/env=DS_ONLINE/" ds.cnf else sed -i "s/env=.*/env=DS_DEV/" ds.cnf fi echo "啓動應用" ./goapp > ./nohup.out
build.shapp
#!/bin/sh cd src/dataservice/ pwd CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a dataservice.go
由於項目結構是:maven
dataservice ├── pkg ├── build.sh └── src ├── dataservice │ └── dataservice.go │ └── start.sh │ └── ds.cnf └── go.mod
而且使用了go modle,若是直接build src/dataservice/dataservice.go文件的話會報錯,提示找不到依賴的包,jenkins pipeline又不支持cd
命令,進不了src/dataservice/
目錄,只能想了個折中的辦法,使用build.sh
腳本執行打包命令。工具