简体   繁体   English

Jenkins 声明性 docker 管道与 angular

[英]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.

相关问题 如何使用Jenkins声明性管道将文件上传到Artifactory - How to upload a file using Jenkins Declarative Pipeline to Artifactory Docker 上的 Jenkins 开始在 Docker 上构建 Angular 应用程序 - Jenkins on Docker start build angular app on docker 验证Jenkins管道中Angular应用程序的覆盖率低 - Verify low coverage of an Angular application in a Jenkins pipeline 使用VSTS管道创建Angular Docker镜像时出现问题 - Issue in creating Angular Docker Image with VSTS Pipeline Jenkins 管道无法识别我的 Angular 项目 - Jenkins pipeline doesn't recognise my Angular project Angular 应用程序部署 IIS 自动化,如使用 Docker/Jenkins 等 - Angular Application Deployment IIS Automation like using Docker/Jenkins etc angular 中的单元测试声明方法 - How unit-test declarative approach in angular Angular 应用程序中声明式和反应式方法之间的摩擦 - Frictions between Declarative and Reactive approach in Angular app Angular 的 Gitlab CI 管道:构建和发布 docker Image./dst 文件夹未找到 - Gitlab CI Pipeline for Angular: Build and Publish docker Image ./dst folder not found ng build命令在詹金斯管道中不起作用 - ng build command not working in jenkins pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM