A
A
Alexey Yarkov2017-12-21 20:03:39
Jenkins
Alexey Yarkov, 2017-12-21 20:03:39

How to output stdout from a script in Jenkins?

I'm trying to install Jenkins on a VPS. The repository has already been cloned and launched in the docker.
I need to execute a couple of commands there just during deployment, in that directory.

pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        slackSend (color: '#FFFF00', message: "TEST STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
        sh 'chmod +x ./sh/*.sh'
        sh 'bash ./sh/postinstall.sh'
        sh 'cp .env.example .env'
        sh 'rm -rf ./node_modules'
        sh 'npm install --from-lock-file --force --no-save'
        sh 'npm run lint'
        sh 'npm run docs'
        sh 'npm run test'
        slackSend (color: '#00FF00', message: "TEST COMPLETED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
      }
    }
    stage('Stage build') {
      when {
        anyOf {
          branch 'dev'
        }
      }
      steps {
        slackSend (color: '#FFFF00', message: "STAGE BUILD STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
        ws('/home/ubuntu/deploy/backend') {
          sh(returnStdout: true, script: 'chmod +x ./sh/*.sh && bash ./sh/stage.sh')
        }
        slackSend (color: '#00FF00', message: "STAGE BUILD COMPLETED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
      }
    }
  }

  environment {
    STAGE_PATH = '/home/ubuntu/deploy/backend'
  }

  post {
    failure {
      slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
    }
  }
}

But at the Stage build step, Jenkins logs one line: /home/ubuntu/deploy/[email protected]
Although running on a local machine, the Docker container build log from the sh/stage.sh script is output to stdout.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SPBMVP, 2017-12-22
@yarkov

dir('/home/ubuntu/deploy/backend/sh') {
    sh "chmod +x stage.sh &&  ./stage.sh"
}

And everything should be output to the console.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question