繁体   English   中英

Jenkins 声明性 docker 管道与 angular

[英]Jenkins declarative docker Pipeline with angular

我在构建 angular 项目的 Jenkins 中运行声明性 docker 管道:

pipeline{
    agent {
        dockerfile {
            label 'linux'
            filename 'Dockerfile'
            args '-u root:root'
        }
    }

我使用npm ci安装 angular npm 依赖项:

stage("build npm dependencies"){
    steps{
        checkout scm
        sh '''npm ci'''
    }
}

但是,构建总是失败,权限被拒绝:

+ 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

我尝试使用 root 用户解决此问题,但仍然失败。 我可以做些什么来解决这个问题?

我使用 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..."
         }
    }
    }
}

我希望这可以帮助您解决您的问题。 有关详细信息,您可以查看我的 GitHub-repo 项目

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM