未找到Jenkins Pipeline"yarn install"命令

Rya*_*Lee 4 jenkins jenkins-pipeline

这是我的第一个Jenkins脚本,它目前在Linux上运行良好但我迁移到MacOS(High Sierra)导致获得shell脚本错误.

节点和纱线包安装在本地Jenkins用户上.我无法弄清楚为什么会发生这种错误,有人能帮我解决这个问题吗?

这是我的Jenkins文件:

node {
  stage('Check out') {
    checkout scm
  }
  stage('Prepare') {
    sh "yarn install"
  }
  stage('Test') {
    sh "yarn test"
  }
  stage('Sonar') {
    if (env.BRANCH_NAME == 'dev') {
      def scannerHome = tool 'sonar scanner';
      withSonarQubeEnv('sonar') {
        sh "${scannerHome}/bin/sonar-scanner"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

完整的日志:

14:43:11 使用hariklee/******连接到https://api.github.com

从6c639bd70ac86cbe6a49ac0b58bcc10e3c64a375获得Jenkinsfile

在耐久性级别中运行:MAX_SURVIVABILITY

[Pipeline]节点

在/ Users/Shared/Jenkins/Home/workspace/wingman_423_ci_cd-7PSSGRAMBTXUQRESYCNVODXU7IZJLJLPHQOE3KYEPCSAAYAFFD4A上的Jenkins上运行

[管道] {

[管道]阶段

[管道] {(退房)

[管道]结账

git rev-parse --is-inside-work-tree #timeout = 10从远程Git存储库中获取更改

git config remote.origin.url https://github.com/wingman-xyz/app.git#timeout = 10

没有标签的提取

https://github.com/wingman-xyz/app.git获取上游更改

git --version #timeout = 10

使用GIT_ASKPASS设置凭据

git fetch --no-tags --progress https://github.com/wingman-xyz/app.git + refs/heads/423_ci_cd:refs/remotes/origin/423_ci_cd

检查修订版6c639bd70ac86cbe6a49ac0b58bcc10e3c64a375(423_ci_cd)

git config core.sparsecheckout #timetime = 10

git checkout -f 6c639bd70ac86cbe6a49ac0b58bcc10e3c64a375

提交消息:"詹金斯测试"

第一次建立.跳过更改日志.

[管道]}

[Pipeline] //阶段

[管道]阶段

[管道] {(准备)

[管道] sh

[wingman_423_ci_cd-7PSSGRAMBTXUQRESYCNVODXU7IZJLJLPHQOE3KYEPCSAAYAFFD4A]运行shell脚本

  • 纱线安装

/Users/Shared/Jenkins/Home/workspace/wingman_423_ci_cd-7PSSGRAMBTXUQRESYCNVODXU7IZJLJLPHQOE3KYEPCSAAYAFFD4A@tmp/durable-cf573520/script.sh:line 2:yarn:command not found

[管道]}

[Pipeline] //阶段

[管道]}

[Pipeline] //节点

[管道]管道终点

GitHub已收到此提交的构建结果的通知

错误:脚本返回退出代码127

完成:失败

Vit*_*nko 8

变量中没有yarn命令PATH.做npm install -g yarn

stage('Prepare') {
    sh "npm install -g yarn"
    sh "yarn install"
}
Run Code Online (Sandbox Code Playgroud)

如果您收到有关未找到npm命令的错误,那么您必须明确地将npm添加到您的PATH使用中withEnv() {}

withEnv(['PATH+NODE=/something=/path/to/node/bin']) {
        stage('Prepare') {
        sh "npm install -g yarn"
        sh "yarn install"
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 通常不建议通过npm安装纱线.使用基于节点的程序包管理器安装Yarn时,程序包未签名,并且执行的唯一完整性检查是基本SHA1哈希,这在安装系统范围的应用程序时存在安全风险.了解更多信息:https://yarnpkg.com/en/docs/install#alternatives-stable (3认同)