title: How to run a go binary as last stage of Jenkins pipeline locally?
body: <p>I have a <a href="https://github.com/eduFDiaz/golang-microservices/blob/master/mvc/app/app.go" rel="nofollow noreferrer">simple gin gonic microservice Golang project</a> that I'm using to learn how to make a Jenkins pipeline. Every stage is successfully run, but the binary is not running after the pipelines finished. Can also tell the process is not running by using curl to hit the endpoint:</p>
  
  <blockquote>
    <p>curl <a href="http://localhost:9191/users" rel="nofollow noreferrer">http://localhost:9191/users</a></p>
  </blockquote>
  
  <p>This is the pipeline in question:</p>
  
  <pre><code>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"
           }
        }
     }
  }
  </code></pre>
  
  <p>The Makefile:</p>
  
  <pre><code>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) &amp;
  all: test build run
  </code></pre>
  
  <p>Everything runs perfectly when I do it by hand. What am I missing here?</p>
  
  <p>Console Output:</p>
  
  <pre><code>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
   &gt; git rev-parse --is-inside-work-tree # timeout=10
  Fetching changes from the remote Git repository
   &gt; 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
   &gt; git --version # timeout=10
   &gt; git fetch --tags --force --progress -- https://github.com/eduFDiaz/golang-microservices.git +refs/heads/*:refs/remotes/origin/* # timeout=10
   &gt; git rev-parse refs/remotes/origin/master^{commit} # timeout=10
   &gt; git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
  Checking out Revision bfa434ff2aca9ea748182aa2b29094e1b9f442c6 (refs/remotes/origin/master)
   &gt; git config core.sparsecheckout # timeout=10
   &gt; git checkout -f bfa434ff2aca9ea748182aa2b29094e1b9f442c6 # timeout=10
   &gt; git branch -a -v --no-abbrev # timeout=10
   &gt; git branch -D master # timeout=10
   &gt; git checkout -b master bfa434ff2aca9ea748182aa2b29094e1b9f442c6 # timeout=10
  Commit message: "run reverted to previous state in Makefile"
   &gt; 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 &amp;
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  Finished: SUCCESS
  </code></pre>