I am running a declarative docker pipeline in Jenkins that builds an angular project:
pipeline{
agent {
dockerfile {
label 'linux'
filename 'Dockerfile'
args '-u root:root'
}
}
I install the angular npm dependencies with npm ci
:
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. 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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.