gitlab及gitlab-runner安装
gitlab
- 安装
- 必须在项目根目录创建本项目的gitlab-ci.yml文件
gitlab-runner
- 安装
-
注册
注册第6步改成 ssh executor
> Please enter the executor: ssh,docker+machine,dockerssh+machine, kubernetes, docker,parallels, virtualbox, docker-ssh, shell:
> ssh
让gitlab-runner ssh到你的测试服务器上 执行自动化脚本
gitlab-ci.ymlgolang例子(测试服和gitlab在一台机器上)
REPO_NAME: dc-server
VERSION: latest
before_script:
- go version
- echo $CI_BUILD_REF
- echo $CI_PROJECT_DIR
stages:
- test
- build
- deploy
test-project:
stage: test
script:
- rm -rf $GOPATH/src/*
- rm -rf $GOPATH/bin/*
- mkdir -p $GOPATH/src/$REPO_NAME
- mv -f src/$REPO_NAME/* $GOPATH/src/$REPO_NAME
- mv -f bin/* $GOPATH/bin/
- cd $GOPATH/src/$REPO_NAME
#- go test $(go list ./... | grep -v /vendor/)
build-project:
stage: build
script:
- mkdir -p $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
- CGO_ENABLED=0 && GOOS=linux && GOARCH=amd64
- cd agent && go build -o $GOPATH/bin/agent
- cd ../battle && go build -o $GOPATH/bin/battle
- cd ../friend && go build -o $GOPATH/bin/friend
- cd ../hall && go build -o $GOPATH/bin/hall
- cd ../world && go build -o $GOPATH/bin/world
- cd ../login && go build -o $GOPATH/bin/login
deploy-project:
stage: deploy
script:
- cd $GOPATH/bin
- mkdir -p logs
- pkill agent && pkill battle && pkill friend && pkill hall && pkill world && pkill login
- nohup ./agent > logs/agent.log 2>&1 &
- nohup ./battle > logs/battle.log 2>&1 &
- nohup ./friend > logs/friend.log 2>&1 &
- nohup ./hall > logs/hall.log 2>&1 &
- nohup ./world > logs/world.log 2>&1 &
- nohup ./login > logs/login.log 2>&1 &
网友评论