我正在使用jhipster设置一个Web应用程序。 我使用jhipster subgenerator创建了一个Jenkins文件,如下所示:
#!/usr/bin/env groovy
node {
stage('checkout') {
checkout scm
}
docker.image('openjdk:8').inside('-u root -e MAVEN_OPTS="-Duser.home=./" --volume=/var/run/docker.sock:/var/run/docker.sock') {
stage('check java') {
sh "java -version"
}
stage('clean') {
sh "chmod +x mvnw"
sh "./mvnw clean"
}
stage('install tools') {
sh "./mvnw com.github.eirslett:frontend-maven-plugin:install-node-and-yarn -DnodeVersion=v6.11.3 -DyarnVersion=v1.1.0"
}
stage('yarn install') {
sh "./mvnw com.github.eirslett:frontend-maven-plugin:yarn"
}
stage('backend tests') {
try {
sh "./mvnw test"
} catch(err) {
throw err
} finally {
junit '**/target/surefire-reports/TEST-*.xml'
}
}
stage('frontend tests') {
try {
sh "./mvnw com.github.eirslett:frontend-maven-plugin:yarn -Dfrontend.yarn.arguments=test"
} catch(err) {
throw err
} finally {
junit '**/target/test-results/karma/TESTS-*.xml'
}
}
stage('packaging') {
sh "./mvnw package -Pprod -DskipTests"
archiveArtifacts artifacts: '**/target/*.war', fingerprint: true
}
}
def dockerImage
stage('build docker') {
sh "cp -R src/main/docker target/"
sh "cp target/*.war target/docker/"
dockerImage = docker.build('test/testrepo', 'target/docker')
}
stage('publish docker') {
docker.withRegistry('http://localhost:5000', 'docker-login') {
dockerImage.push 'latest'
}
}
}
执行时和jenkins失败(权限被拒绝):
sh "cp -R src/main/docker target/"
这是Jenkins上的工作区目录:
-rw-r--r-- 1 jenkins jenkins 1565 Jan 2 18:58 .angular-cli.json
-rw-r--r-- 1 jenkins jenkins 475 Jan 2 18:58 .editorconfig
drwxr-xr-x 8 jenkins jenkins 4096 Jan 2 19:28 .git
-rw-r--r-- 1 jenkins jenkins 3374 Jan 2 18:58 .gitattributes
-rw-r--r-- 1 jenkins jenkins 1931 Jan 2 18:58 .gitignore
drwxr-xr-x 4 root root 4096 Jan 2 18:59 .m2
drwxr-xr-x 3 jenkins jenkins 4096 Jan 2 18:58 .mvn
-rw-r--r-- 1 jenkins jenkins 1171 Jan 2 18:58 .yo-rc.json
-rw-r--r-- 1 jenkins jenkins 1832 Jan 2 18:58 Jenkinsfile
-rw-r--r-- 1 jenkins jenkins 7052 Jan 2 18:58 README.md
-rwxr-xr-x 1 jenkins jenkins 7058 Jan 2 19:28 mvnw
-rw-r--r-- 1 jenkins jenkins 5006 Jan 2 18:58 mvnw.cmd
drwxr-xr-x 3 root root 4096 Jan 2 19:29 node
drwxr-xr-x 1120 root root 36864 Jan 2 19:29 node_modules
-rw-r--r-- 1 jenkins jenkins 4434 Jan 2 18:58 package.json
-rw-r--r-- 1 jenkins jenkins 49644 Jan 2 18:58 pom.xml
-rw-r--r-- 1 jenkins jenkins 37 Jan 2 18:58 postcss.config.js
-rw-r--r-- 1 jenkins jenkins 117 Jan 2 18:58 proxy.conf.json
drwxr-xr-x 4 jenkins jenkins 4096 Jan 2 18:58 src
drwxr-xr-x 8 root root 4096 Jan 2 19:30 target
-rw-r--r-- 1 jenkins jenkins 616 Jan 2 18:58 tsconfig-aot.json
-rw-r--r-- 1 jenkins jenkins 737 Jan 2 18:58 tsconfig.json
-rw-r--r-- 1 jenkins jenkins 3068 Jan 2 18:58 tslint.json
drwxr-xr-x 2 jenkins jenkins 4096 Jan 2 18:58 webpack
-rw-r--r-- 1 jenkins jenkins 310798 Jan 2 19:29 yarn.lock
目标目录是否应该具有用户/组(root:root)? 解决这个问题的最佳方法是什么?
答案 0 :(得分:0)
jenkins无权在目标目录中写入。
1 - 您可以添加jenkins作为目标目录的第二个所有者,例如:
chown -R root:jenkins target/
(在你的jenkinsfile中:sh 'chown -R root:jenkins target/'