[英]Jenkins declarative docker Pipeline with angular
I am running a declarative docker pipeline in Jenkins that builds an angular project:我在构建 angular 项目的 Jenkins 中运行声明性 docker 管道:
pipeline{
agent {
dockerfile {
label 'linux'
filename 'Dockerfile'
args '-u root:root'
}
}
I install the angular npm dependencies with npm ci
:我使用npm ci
安装 angular npm 依赖项:
stage("build npm dependencies"){
steps{
checkout scm
sh '''npm ci'''
}
}
However, the build always fails with permission denied:但是,构建总是失败,权限被拒绝:
+ npm ci
npm ERR! code 1
npm ERR! path /opt/jenkins/project/project_ui-project_feat_build/node_modules/cypress
npm ERR! command failed
npm ERR! command sh -c node index.js --exec install
npm ERR! Cypress cannot write to the cache directory due to file permissions
npm ERR! Failed to access /root/.cache/Cypress:
npm ERR!
npm ERR! EACCES: permission denied, mkdir
I tried to resolve this using the root user, but still it fails.我尝试使用 root 用户解决此问题,但仍然失败。 What can I do to resolve this issue?我可以做些什么来解决这个问题?
I worked with angular and I built a pipeline using jenkinsfile, this can help you to start from checkout, install dependencies, build, archive and deploy.我使用 angular 并使用 jenkinsfile 构建了一个管道,这可以帮助您从结帐、安装依赖项、构建、存档和部署开始。
pipeline {
agent any
tools {nodejs "node"}
/*environment {
PATH='/usr/local/bin:/usr/bin:/bin'
}*/
stages{
stage('Checkout') {
//disable to recycle workspace data to save time/bandwidth
steps{
deleteDir()
checkout scm
}
//enable for commit id in build number
//env.git_commit_id = sh returnStdout: true, script: 'git rev-parse HEAD'
//env.git_commit_id_short = env.git_commit_id.take(7)
//currentBuild.displayName = "#${currentBuild.number}-${env.git_commit_id_short}"
}
stage('NPM Install') {
/*withEnv(["NPM_CONFIG_LOGLEVEL=warn"]) {*/
steps{
sh 'npm install'
sh 'npm install -g @angular/cli@1.0.2'
sh 'ng --version'
}
/*}*/
}
stage('Build') {
steps{
milestone(20)
sh 'ng build --prod'
}
}
stage('Archive') {
steps{
sh 'tar -cvzf dist.tar.gz --strip-components=1 dist'
archive 'dist.tar.gz'
}
}
stage('Deploy') {
steps{
milestone(20)
echo "Deploying..."
}
}
}
}
I hope that can help you to resolve your issue.我希望这可以帮助您解决您的问题。 For more details about that you can check my GitHub-repo project有关详细信息,您可以查看我的 GitHub-repo 项目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.