首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在本地运行go二进制文件作为Jenkins管道的最后阶段?

如何在本地运行go二进制文件作为Jenkins管道的最后阶段?
EN

Stack Overflow用户
提问于 2020-04-22 23:16:51
回答 1查看 730关注 0票数 1

我有一个简单的gin gonic微服务Golang项目,我正在使用它来学习如何制作Jenkins管道。每个阶段都成功运行,但是二进制文件在管道完成后不会运行。还可以通过使用curl访问端点来判断进程是否正在运行:

卷曲http://localhost:9191/users

这是一条有争议的管道:

代码语言:javascript
复制
pipeline {
   agent any

   stages {
      stage('git') {
         steps {
            echo "git"
            git 'https://github.com/eduFDiaz/golang-microservices.git'
         }
      }
      stage('clean') {
         steps {
            echo "clean"
            sh "make clean"
         }
      }
      stage('test') {
         steps {
            echo "test"
            sh "make test"
         }
      }
      stage('build') {
         steps {
            echo "build"
            sh "make build"
         }
      }
      stage('run') {
         steps {
            echo "run"
            sh "make run"
         }
      }
   }
}

The Makefile:

代码语言:javascript
复制
executableName=testApi
clean:
    echo "stoping if running and cleaning"
    rm -rf ./bin
    killall $(executableName) || true
test:
    echo "Testing..."
    go test -coverprofile cp.out ./mvc/...
    go tool cover -html=cp.out
build:
    echo "Building..."
    go build -o bin/$(executableName) mvc/main.go
run:
    echo "Running..."
    ./bin/$(executableName) &
all: test build run

当我用手做的时候,一切都很完美。我在这里错过了什么?

控制台输出:

代码语言:javascript
复制
Started by user Eduardo fernandez
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /root/.jenkins/workspace/golang pipeline test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (git)
[Pipeline] echo
git
[Pipeline] git
No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/eduFDiaz/golang-microservices.git # timeout=10
Fetching upstream changes from https://github.com/eduFDiaz/golang-microservices.git
 > git --version # timeout=10
 > git fetch --tags --force --progress -- https://github.com/eduFDiaz/golang-microservices.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision bfa434ff2aca9ea748182aa2b29094e1b9f442c6 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f bfa434ff2aca9ea748182aa2b29094e1b9f442c6 # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master bfa434ff2aca9ea748182aa2b29094e1b9f442c6 # timeout=10
Commit message: "run reverted to previous state in Makefile"
 > git rev-list --no-walk bfa434ff2aca9ea748182aa2b29094e1b9f442c6 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (clean)
[Pipeline] echo
clean
[Pipeline] sh
+ make clean
echo "stoping if running and cleaning"
stoping if running and cleaning
rm -rf ./bin
killall testApi || true
testApi: no process found
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (test)
[Pipeline] echo
test
[Pipeline] sh
+ make test
echo "Testing..."
Testing...
go test -coverprofile cp.out ./mvc/...
?       github.com/golang-microservices/mvc [no test files]
?       github.com/golang-microservices/mvc/app [no test files]
?       github.com/golang-microservices/mvc/controllers [no test files]
ok      github.com/golang-microservices/mvc/domain  0.004s  coverage: 0.0% of statements
ok      github.com/golang-microservices/mvc/services    0.003s  coverage: 0.0% of statements [no tests to run]
?       github.com/golang-microservices/mvc/utils   [no test files]
go tool cover -html=cp.out
HTML output written to /tmp/cover914928629/coverage.html
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] echo
build
[Pipeline] sh
+ make build
echo "Building..."
Building...
go build -o bin/testApi mvc/main.go
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (run)
[Pipeline] echo
run
[Pipeline] sh (hide)
+ make run
echo "Running..."
Running...
./bin/testApi &
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-23 02:30:46

发生此问题是因为Jenkins正在清理在构建过程中启动的所有子进程。也就是说,make正在启动应用程序,但Jenkins作为清理的一部分正在终止该进程(有关详细信息,请搜索"ProcessTreeKiller")。

要解决以下更新行的问题,请执行以下操作

代码语言:javascript
复制
stage('run') {
steps {
echo "run"
sh "export JENKINS_NODE_COOKIE=dontKillMe; make run "
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61376710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档