[英]jenkins pipeline nodeJs
我的 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
我還使用管道插件在 jenkins 2.0 上的安裝節點中嘗試了解決方案
並且它拋出 Expected to find 'someKey "someValue"' @ line 4, column 7. node { 錯誤。 但我仍然在 jenkins 上遇到 npm not found 錯誤。 我是詹金斯的新手,因此感謝您的任何幫助。 提前致謝
我能夠解決這些問題。 按照以下鏈接,並能夠解決該問題。 https://medium.com/@gustavo.guss/jenkins-starting-with-pipeline-doing-a-node-js-test-72c6057b67d4
它是一個謎題。 ;)
有一點參考技巧。
您需要配置 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'
}
}
}
}
要研究的完整案例: Gustavo Apolinario 在 Medium 上發帖
希望能幫助到你!
如果你需要不同版本的 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.