Use 'input' in a non-blocking way

131 views
Skip to first unread message

Sean Liu

unread,
Jan 23, 2018, 10:26:25 PM1/23/18
to Jenkins Users
Hi,

I am trying to setup a cd pipeline with Jenkins recently, and 'input' is used for manual approval  in the pipeline, but it seems that 'input' blocks the executor and won't free the executor util the build is manually approved or cancelled, the pipeline is something like this:

pipeline {
  agent any

  stages {
    stage('build docker container') {
      steps {
        sh 'docker-compose build'
        sh 'docker-compose run start_dependencies'
      }
    }

    stage('prepare database') {
      steps {
        sh 'docker-compose run --rm rails bundle exec rails db:create'
        sh 'docker-compose run --rm rails bundle exec rails db:migrate'
      }
    }

    stage('coding style check') {
      steps {
        sh 'docker-compose run --rm rails bundle exec rubocop'
      }
    }

    stage('automated tests') {
      steps {
        sh 'docker-compose run --rm rails bundle exec rspec'
      }
    }


    stage('deploy to staging') {
      when {
        branch "master"
      }
      
      steps {
        input 'deploy to staging?'
        lock(resource: 'staging-server', inversePrecedence: true) {
          sshagent (credentials: ['a99a855d-e3c8-484c-82ce-f9f6f0fd0ffc']) {
            sh 'docker-compose run -u $(id -u $USER):$(id -g $USER) -v /var/lib/jenkins:/var/lib/jenkins -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro -v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent -e COMMIT=$GIT_COMMIT --rm rails bundle exec mina staging deploy'
          }
        }
      }
    }


  }

  post {
    always {
      sh 'docker-compose kill'
      sh 'docker-compose rm -fv'
    }
  }
}Enter code here...

I tried to pull the 'input' statement out of 'deploy to staging' like this:

stage('approve for deploying to staging') {
  steps {
    input 'deploy to staging?'
  }
}

it still doesn't work, is there a way to use 'input' in a non-blocking way?

Thanks!


Victor Martinez

unread,
Jan 24, 2018, 6:23:26 AM1/24/18
to Jenkins Users
Reply all
Reply to author
Forward
0 new messages