首页 文章

找不到Jenkins管道“纱线安装”命令

提问于
浏览
2

这是我的第一个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"
      }
    }
  }
}

和完整的日志:

14:43:11使用hariklee连接到https://api.github.com / ******从6c639bd70ac86cbe6a49ac0b58bcc10e3c64a375获取Jenkinsfile在Durability级别运行:MAX_SURVIVABILITY [Pipeline]节点在/ Users / Shared / Jenkins中的Jenkins上运行/ Home / workspace / wingman_423_ci_cd-7PSSGRAMBTXUQRESYCNVODXU7IZJLJLPHQOE3KYEPCSAAYAFFD4A [Pipeline] {[Pipeline] stage [Pipeline] {(Check out)[Pipeline] checkout 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 #timeout = 10 git checkout -f 6c63 9bd70ac86cbe6a49ac0b58bcc10e3c64a375提交消息:“jenkins test”第一次构建 . 跳过更改日志 . [Pipeline]} [Pipeline] // stage [Pipeline] stage [Pipeline] {(Prepare)[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] // stage [Pipeline]} [Pipeline] // node [Pipeline] End of Pipeline GitHub已收到通知commit的构建结果错误:脚本返回退出代码127完成:FAILURE

1 回答

  • 6

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

    stage('Prepare') {
        sh "npm install -g yarn"
        sh "yarn install"
    }
    

    如果您收到有关未找到 npm 命令的错误,则必须使用withEnv() {}将_pm显式添加到 PATH

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

相关问题