sai*_*ini 1 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'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我试图在我的 jenkins 节点上设置 NodeJs。我安装了nodejs插件并编写了脚本
pipeline {
agent any
stages {
stage('Build') {
steps {
nodejs(nodeJSInstallationName: 'Node 6.x', configId: '<config-file-provider-id>') {
sh 'npm config ls'
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如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
小智 7
它是一个谜题。;)
有一点参考技巧。
您需要配置 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'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
要研究的完整案例:Gustavo Apolinario 在 Medium 上发帖
希望能帮助到你!
| 归档时间: |
|
| 查看次数: |
13201 次 |
| 最近记录: |