【问题标题】:jenkins pipeline nodeJs詹金斯管道nodeJs
【发布时间】:2018-11-28 20:33:02
【问题描述】:

我的 JenkinsFile 脚本开始抛出 npm not found 错误。 (它适用于 maven,但在 npm 失败)

    pipeline {
    environment {
    JENKINS='true'
     }
       agent any 
       stages{
    stage('change permissions') {
    steps {
        sh "chmod 777 ./mvnw "
    }
}

    stage('clean') {
    steps {
        sh './mvnw clean install'
    }
    }


    stage('yarn install') {
    steps{
        sh 'npm install -g yarn'
        sh 'yarn install'
    }
    }
    stage('yarn webpack:build') {
    steps {
        sh 'yarn webpack:build'
    }
    }

    stage('backend tests') {
    steps {
        sh './mvnw test'
    }
    }

    stage('frontend tests') {
    steps {
        sh 'yarn test'
    }
    }

    }
}

解决这个问题 我正在尝试在我的 jenkins 节点上设置 NodeJs。我安装了nodejs插件并编写了脚本

pipeline {
agent any

stages {
    stage('Build') {
        steps {
            nodejs(nodeJSInstallationName: 'Node 6.x', configId: '<config-file-provider-id>') {
                sh 'npm config ls'
            }
        }
    }
}
}

https://wiki.jenkins.io/display/JENKINS/NodeJS+Plugin所示 我还在全局工具配置中设置了 nodejs

我也尝试了installing node on jenkins 2.0 using the pipeline plugin中的解决方案

它抛出 预计会在第 4 行第 7 列找到‘someKey "someValue"'。 节点{ 错误。 但我仍然在 jenkins 上收到 npm not found 错误。我是詹金斯的新手,因此不胜感激。 提前致谢

我能够解决这些问题。按照以下链接并能够解决该问题。 https://medium.com/@gustavo.guss/jenkins-starting-with-pipeline-doing-a-node-js-test-72c6057b67d4

【问题讨论】:

  • 如果不了解您的项目设置,这真的很难回答。您应该提供更多信息或在 Google 上解决问题。
  • 我已经编辑了帖子并提供了更多信息,如果它可以帮助您更多地了解我的问题,请告诉我
  • 您提到您能够解决问题 - 我认为您应该发布该链接并附上简短的解释,作为下一位前来寻找此问题的人的答案。很高兴你让它工作了!
  • @saiharshini - 你得到yarn 命令工作了吗?如果有,怎么做?
  • @kwhitejr medium.com/@gustavo.guss/… 我按照本网站的说明进行操作。在我的文件中,一旦我添加它对我有用,我就丢失了“工具 {nodejs “node”}”。

标签: node.js jenkins-pipeline


【解决方案1】:

这是一个谜题。 ;)

有一点参考技巧。

您需要配置您的 jenkins 才能看到您的 nodejs 配置名称。

在全局工具配置中,您需要定义节点配置名称。它参考了您的 Jenkinsfile 参考。

参考 Jenkingsfile 改编示例:

pipeline {
  agent any

  tools {nodejs "node"}

  stages {    
    stage('Cloning Git') {
      steps {
        git 'https://github.com/xxxx'
      }
    }        
    stage('Install dependencies') {
      steps {
        sh 'npm i -save express'
      }
    }     
    stage('Test') {
      steps {
         sh 'node server.js'
      }
    }             
  }
}

要研究的完整案例:Post at Medium by Gustavo Apolinario

希望对你有帮助!

【讨论】:

    【解决方案2】:

    如果你需要不同版本的 Node.js 和 npm,你可以为 Jenkins 安装 NodeJS 插件。 转到Manage Jenkins -&gt; Global tools configuration 并找到NodeJS 部分。 选择您需要的版本并根据需要命名。也可以添加需要全局安装的 npm 包。

    在声明式管道中,只需引用正确版本的 node.js 即可使用:

    stage('Review node and npm installations') {
      steps {
        nodejs(nodeJSInstallationName: 'node13') {
          sh 'npm -v'  //substitute with your code
          sh 'node -v'
        }
      }
    }
    

    此处为完整示例:https://pillsfromtheweb.blogspot.com/2020/05/how-to-use-different-nodejs-versions-on.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2017-05-24
      • 1970-01-01
      • 2017-09-06
      相关资源
      最近更新 更多