我编写了一个Jenkins管道,相关部分如下所示:
pipeline {
agent {
dockerfile true
}
triggers {
pollSCM('H 1 * * 1-5')
}
options {
buildDiscarder(logRotator(artifactNumToKeepStr: "${NUMBER_OF_ARTIFACTS_TO_KEEP}"))
disableConcurrentBuilds()
timeout(time: 60, unit: 'MINUTES')
timestamps()
}
stages {
stage('Metadata') {
steps {
script {
sh 'java -version'
}
script {
sh './mvnw -v'
}
}
}
stage('Build') {
steps {
script {
sh './mvnw --batch-mode clean install'
}
}
}
stage('Archive artifacts (develop/master)') {
when {
anyOf {
branch 'master'
branch 'develop'
}
}
steps {
script {
sh './package.sh'
}
archive '**/target/*.jar'
archiveArtifacts artifacts: '*.deb'
}
}
}
post {
always {
deleteDir()
}
failure {
sendNotifications currentBuild.result
}
unstable {
sendNotifications currentBuild.result
}
}
}
我的Dockerfile:
FROM alpine
RUN apk add --no-cache dpkg openjdk8
所有脚本运行良好,除了 package.sh,我在输出中得到以下日志:
07:47:25 [chx-sync_-sync_master-A2F53LY4I2X54TLDEU2Z2PXI423NI6FODHQDS7CRIKCCNDF5UGOA]运行shell脚本 07:47:25 + ./package.sh 07:47:25 /home/jenkins/jenkins/workspace/chx-sync_-sync_master-A2F53LY4I2X54TLDEU2Z2PXI423NI6FODHQDS7CRIKCCNDF5UGOA@tmp/durable-dbcb4143/script.sh:line 1:./ package.sh:not found
我无法弄清楚为什么除了这个脚本之外的所有脚本都能正常工作。它们都位于Git项目的根目录中。我的管道中是否有一些命令会改变工作目录,或者这里发生了什么?
修改
我猜猜package.sh中的shebang可能有用吗?它是#!/bin/bash
。