Jenkins管道没有打印完整的日志

时间:2017-03-31 15:28:39

标签: logging jenkins makefile jenkins-pipeline

我有一个Makefile:

.PHONE: test
REMOVE_IMG_ON_FAIL=true
REMOVE_IMG_WHEN_DONE=true
DOCKER_OPTS = --rm -t
test: test-ubuntu14 test-ubuntu16 test-centos6 test-centos7

test-ubuntu14:
        $(eval ID:=$(shell docker build -f tests/Dockerfile-ubuntu14.04 . | tee /dev/stderr | awk 'END {print $$NF}'))
        docker run ${DOCKER_OPTS} -v ${PWD}/tests/hosts:/etc/hosts ${ID} \
                /ansible-role-this/tests/test.sh || { ${REMOVE_IMG_ON_FAIL} && docker rmi ${ID} && exit 1 ; }
        { ${REMOVE_IMG_WHEN_DONE} && docker rmi ${ID} ; } || true

test-ubuntu16:
        $(eval ID:=$(shell docker build -f tests/Dockerfile-ubuntu16.04 . | tee /dev/stderr | awk 'END {print $$NF}'))
        docker run ${DOCKER_OPTS} -v ${PWD}/tests/hosts:/etc/hosts ${ID} \
                /ansible-role-this/tests/test.sh || { ${REMOVE_IMG_ON_FAIL} && docker rmi ${ID} && exit 1 ; }
        { ${REMOVE_IMG_WHEN_DONE} && docker rmi ${ID} ; } || true

test-centos6:
        $(eval ID:=$(shell docker build -f tests/Dockerfile-centos6 . | tee /dev/stderr | awk 'END {print $$NF}'))
        docker run ${DOCKER_OPTS} -v ${PWD}/tests/hosts:/etc/hosts ${ID} \
                /ansible-role-this/tests/test.sh || { ${REMOVE_IMG_ON_FAIL} && docker rmi ${ID} && exit 1 ; }
        { ${REMOVE_IMG_WHEN_DONE} && docker rmi ${ID} ; } || true

test-centos7:
        $(eval ID:=$(shell docker build -f tests/Dockerfile-centos7 . | tee /dev/stderr | awk 'END {print $$NF}'))
        docker run ${DOCKER_OPTS} -v ${PWD}/tests/hosts:/etc/hosts ${ID} \
                /ansible-role-this/tests/test.sh || { ${REMOVE_IMG_ON_FAIL} && docker rmi ${ID} && exit 1 ; }
        { ${REMOVE_IMG_WHEN_DONE} && docker rmi ${ID} ; } || true

与Jenkinsfile一起

node {
  stage 'Checkout'
  checkout scm

  stage 'test'
  catchError {
    wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
      sh 'make test'
    }
  }
  step([$class: 'Mailer',
       notifyEveryUnstableBuild: true,
       recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
                                       [$class: 'RequesterRecipientProvider']])])
}

它工作正常,但由于某些原因,管道只打印第一个 test-ubuntu14 输出,但不打印其余部分。虽然他们肯定被执行了。不幸的是,这使调试过程变得复杂。

更新:作为解决方法,我使用了这个Jenkins文件:

node {
  stage 'Checkout'
  checkout scm

  stage 'test'
  catchError {
    wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
      sh 'make test-ubuntu14'
      sh 'make test-ubuntu16'
      sh 'make test-centos6'
      sh 'make test-centos7'
    }
  }
  step([$class: 'Mailer',
       notifyEveryUnstableBuild: true,
       recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
                                       [$class: 'RequesterRecipientProvider']])])
}

无论如何,我仍然想知道如何打印单一品牌测试的输出。

1 个答案:

答案 0 :(得分:1)

尝试将输出变为变量: result = sh script:'make test-ubuntu14',returnStdout:true

刚打印变量 打印结果