詹金斯管道节点

时间:2018-06-19 19:42:50

标签: node.js jenkins-pipeline

我的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节点上设置NodeJ。我安装了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中所示 我还在全局工具config上设置了nodejs

我还在installing node on jenkins 2.0 using the pipeline plugin

中尝试了该解决方案

它会抛出 预计在第4行第7列找到“ someKey“ someValue””。     节点{ 错误。 但是我仍然在詹金斯上得到npm not found错误。我是jenkins的新手,因此感谢您的帮助。 预先感谢

我能够解决问题。点击了以下链接,并能够解决此问题。 https://medium.com/@gustavo.guss/jenkins-starting-with-pipeline-doing-a-node-js-test-72c6057b67d4

2 个答案:

答案 0 :(得分:0)

这是一个难题。 ;)

有一些 reference 技巧。

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

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

Image from Gustavo Apolinario post at Medium

参考以下代码,查找一个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

希望有帮助!

答案 1 :(得分:0)

如果需要不同版本的Node.js和npm,则可以为Jenkins安装NodeJS插件。 转到Manage Jenkins -> 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