Jenkins 构建Golang项目记录

路遥

jenkins.sh:

#!/bin/bash
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64


pid=`ps -ef | grep jenkins.war | grep -v 'grep'| awk '{print $2}'| wc -l`
  if [ "$1" = "start" ];then
  if [ $pid -gt 0 ];then
  echo 'jenkins is running...'
else
  nohup java -jar jenkins.war > jenkins.log --httpPort=8080  2>&1 &
  fi
  elif [ "$1" = "stop" ];then
  exec ps -ef | grep jenkins | grep -v grep | awk '{print $2}'| xargs kill -9
  echo 'jenkins is stop..'
else
  echo "Please input like this:"./jenkins.sh start" or "./jenkins stop""
  fi

开启 ./jenkins.sh start
停止 ./jenkins.sh stop

start.sh

#!/bin/bash

export BUILD_ID=dontKillMe
export ENV=test
export GOPROXY=https://goproxy.cn,direct
export GO111MODULE=on
export GOPATH=/opt/go
export GOROOT=/usr/lib/golang

pid=$(netstat -nlp | grep :8081 | awk '{print $7}' | awk -F"/" '{ print $1 }');

if [ -n "$pid" ];then
   kill -9 $pid
fi

cd /opt/go/src/dearm
git pull
go build main.go
mv main /opt/dearm
nohup /opt/dearm >> /opt/log/dearm.log 2>&1 &

使用nohup运行项目,一定要加环境变量export BUILD_ID=dontKillMe

go目录: /opt/go/src/项目

jenkins 添加gitee插件
image.png
image.png
image.png
image.png
image.png

阅读 189
1 声望
0 粉丝
0 条评论
你知道吗?

1 声望
0 粉丝
宣传栏