像Typecheck测试的纱线命令不在Jenkins Slave中不起作用

发布于 2025-02-05 07:29:43 字数 4375 浏览 5 评论 0原文

我面临着詹金斯(Jenkins)构建中的错误,这是自过去3周以来发生的令人沮丧的问题使用我们自己的共享库,这并不是所有

错误的工作:对于命令纱线Typecheck,Prettier:检查,测试,CI等路径

+yarn typecheck
yarn run v1.22.17
$ tsc --noEmit
/bin/sh: tsc: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  def jenkins

  DuploPipeline(jenkins) {
    this.jenkins = jenkins
  }

  jenkins.steps.node('docker-nodejs-slave') {
    jenkins.steps.withEnv(['NODEJS_VERSION=16','NPM_AUTH_KEY = ""','NPM_EMAIL = ""',]) {
      jenkins.steps.stage('Install dependencies') {
        jenkins.steps.sh 'yarn'
      }

  jenkins.steps.stage('Check types') {
    jenkins.steps.checkout jenkins.scm
     jenkins.steps.sh '''
       export PATH=$(npm bin -g):$PATH >> ~/.profile
       echo $PATH
       which yarn
       ls -l /tools/nodejs/node-v16-linux-x64/bin
       yarn typecheck;
     '''
            }

的输出具有Nodejs安装的位置-Node-V16-Linux-x64 is我的nodejs安装,接下来您可以看到bin下的文件

/tools/nodejs/node-v16-linux-x64/bin:/tools/fortify/Fortify_SCA_and_Apps_19.2.0/bin:/tools/awscli/awscli-1/lib/aws/bin:/tools/awscli/sessionmanagerplugin/bin:/tools/nodejs/node-v16-linux-x64/bin:/tools/fortify/Fortify_SCA_and_Apps_20.1.4/bin:/tools/awscli/awscli-1/lib/aws/bin:/tools/awscli/sessionmanagerplugin/bin:/usr/local/bin:/usr/bin:/tools/awscli/aws-cli-saml:/tools/awscli/aws-cli-saml

node-v16-linux-x64/bin

total 78432
lrwxrwxrwx. 1 1001 1001       35 Feb 25 05:32 bower -> ../lib/node_modules/bower/bin/bower
lrwxrwxrwx. 1 1001 1001       45 Feb  8 12:49 corepack -> ../lib/node_modules/corepack/dist/corepack.js
lrwxrwxrwx. 1 1001 1001       35 Feb 25 05:32 dredd -> ../lib/node_modules/dredd/bin/dredd
lrwxrwxrwx. 1 1001 1001       39 Feb 25 05:32 ember -> ../lib/node_modules/ember-cli/bin/ember
lrwxrwxrwx. 1 1001 1001       39 Feb 25 05:32 grunt -> ../lib/node_modules/grunt-cli/bin/grunt
lrwxrwxrwx. 1 1001 1001       36 Feb 25 05:32 gulp -> ../lib/node_modules/gulp/bin/gulp.js
lrwxrwxrwx. 1 1001 1001       40 Apr 23 05:01 newman -> ../lib/node_modules/newman/bin/newman.js
lrwxrwxrwx. 1 root root       62 Apr 23 05:01 newman-reporter-htmlextra -> ../lib/node_modules/newman-reporter-htmlextra/bin/htmlextra.js
lrwxrwxrwx. 1 1001 1001       38 Feb  8 12:49 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx. 1 1001 1001       38 Feb 25 05:32 npm-cache -> ../lib/node_modules/npm-cache/index.js
lrwxrwxrwx. 1 1001 1001       38 Feb  8 12:49 npx -> ../lib/node_modules/npm/bin/npx-cli.js
lrwxrwxrwx. 1 1001 1001       52 Feb 25 05:32 phantomjs -> ../lib/node_modules/phantomjs-prebuilt/bin/phantomjs
lrwxrwxrwx. 1 1001 1001       37 Feb 25 05:32 retire -> ../lib/node_modules/retire/bin/retire
lrwxrwxrwx. 1 1001 1001       36 Feb 25 05:32 yarn -> ../lib/node_modules/yarn/bin/yarn.js
lrwxrwxrwx. 1 1001 1001       36 Feb 25 05:32 yarnpkg -> ../lib/node_modules/yarn/bin/yarn.js
lrwxrwxrwx. 1 1001 1001       33 Feb 25 05:32 yo -> ../lib/node_modules/yo/lib/cli.js
lrwxrwxrwx. 1 1001 1001       46 Feb 25 05:32 yo-complete -> ../lib/node_modules/yo/lib/completion/index.js
-rwxr-xr-x. 1 1001 1001 80310904 Feb  8 12:49 node

的输出

/tools/nodejs/node-v16.14.0-linux-x64/bin/yarn

命令 yarn 所有内容 对我来说似乎还不错,但是错误仍然

奇怪地发生,当我编写示例作业时,它运行良好

pipeline {
  agent none
  stages {
    stage('NodeJS Build') {
      agent {
        node { label 'docker-nodejs-slave' }
      }
      steps {
        script {
          env.NPM_AUTH_KEY = ' '
          env.NPM_EMAIL = ' '
          sh '''
            export NODEJS_VERSION=16
            source /etc/profile.d/jenkins.sh
            npm -v
            node -v
            yarn typecheck;
          '''
        }
      }
    }
  }
}

+npm -v
8.3.1
+node -v
v16.14.0
+yarn typecheck
yarn run v1.22.17
$ tsc --noEmit
Done in 17.01s.
+yarn prettier:check
yarn run v1.22.17
$ prettier -l 'src/**/*.{js,ts,tsx}'
Done in 7.18s.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS

但是,为什么在我的API Jenkins管道中使用共享库是一个很大的问题,我正在使用相同的从属对于两者,我在声明性的管道中缺少一些东西,请帮助我解决这个问题。

I am facing below errors in my jenkins builds, this is a frustrating issue happening since past 3 weeks, no matter how much i try, i am unable to get these commands worked, in the local they work fine, but thru the jenkins pipeline code using our own shared libraries, this does not work at all

ERROR: for the command yarn typecheck, same happens with prettier:check, test, ci etc

+yarn typecheck
yarn run v1.22.17
$ tsc --noEmit
/bin/sh: tsc: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  def jenkins

  DuploPipeline(jenkins) {
    this.jenkins = jenkins
  }

  jenkins.steps.node('docker-nodejs-slave') {
    jenkins.steps.withEnv(['NODEJS_VERSION=16','NPM_AUTH_KEY = ""','NPM_EMAIL = ""',]) {
      jenkins.steps.stage('Install dependencies') {
        jenkins.steps.sh 'yarn'
      }

  jenkins.steps.stage('Check types') {
    jenkins.steps.checkout jenkins.scm
     jenkins.steps.sh '''
       export PATH=$(npm bin -g):$PATH >> ~/.profile
       echo $PATH
       which yarn
       ls -l /tools/nodejs/node-v16-linux-x64/bin
       yarn typecheck;
     '''
            }

The output of PATH has the location of nodejs installation - node-v16-linux-x64 is my nodejs installation and next you can see the files under the bin

/tools/nodejs/node-v16-linux-x64/bin:/tools/fortify/Fortify_SCA_and_Apps_19.2.0/bin:/tools/awscli/awscli-1/lib/aws/bin:/tools/awscli/sessionmanagerplugin/bin:/tools/nodejs/node-v16-linux-x64/bin:/tools/fortify/Fortify_SCA_and_Apps_20.1.4/bin:/tools/awscli/awscli-1/lib/aws/bin:/tools/awscli/sessionmanagerplugin/bin:/usr/local/bin:/usr/bin:/tools/awscli/aws-cli-saml:/tools/awscli/aws-cli-saml

The files under bin location of node-v16-linux-x64/bin

total 78432
lrwxrwxrwx. 1 1001 1001       35 Feb 25 05:32 bower -> ../lib/node_modules/bower/bin/bower
lrwxrwxrwx. 1 1001 1001       45 Feb  8 12:49 corepack -> ../lib/node_modules/corepack/dist/corepack.js
lrwxrwxrwx. 1 1001 1001       35 Feb 25 05:32 dredd -> ../lib/node_modules/dredd/bin/dredd
lrwxrwxrwx. 1 1001 1001       39 Feb 25 05:32 ember -> ../lib/node_modules/ember-cli/bin/ember
lrwxrwxrwx. 1 1001 1001       39 Feb 25 05:32 grunt -> ../lib/node_modules/grunt-cli/bin/grunt
lrwxrwxrwx. 1 1001 1001       36 Feb 25 05:32 gulp -> ../lib/node_modules/gulp/bin/gulp.js
lrwxrwxrwx. 1 1001 1001       40 Apr 23 05:01 newman -> ../lib/node_modules/newman/bin/newman.js
lrwxrwxrwx. 1 root root       62 Apr 23 05:01 newman-reporter-htmlextra -> ../lib/node_modules/newman-reporter-htmlextra/bin/htmlextra.js
lrwxrwxrwx. 1 1001 1001       38 Feb  8 12:49 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx. 1 1001 1001       38 Feb 25 05:32 npm-cache -> ../lib/node_modules/npm-cache/index.js
lrwxrwxrwx. 1 1001 1001       38 Feb  8 12:49 npx -> ../lib/node_modules/npm/bin/npx-cli.js
lrwxrwxrwx. 1 1001 1001       52 Feb 25 05:32 phantomjs -> ../lib/node_modules/phantomjs-prebuilt/bin/phantomjs
lrwxrwxrwx. 1 1001 1001       37 Feb 25 05:32 retire -> ../lib/node_modules/retire/bin/retire
lrwxrwxrwx. 1 1001 1001       36 Feb 25 05:32 yarn -> ../lib/node_modules/yarn/bin/yarn.js
lrwxrwxrwx. 1 1001 1001       36 Feb 25 05:32 yarnpkg -> ../lib/node_modules/yarn/bin/yarn.js
lrwxrwxrwx. 1 1001 1001       33 Feb 25 05:32 yo -> ../lib/node_modules/yo/lib/cli.js
lrwxrwxrwx. 1 1001 1001       46 Feb 25 05:32 yo-complete -> ../lib/node_modules/yo/lib/completion/index.js
-rwxr-xr-x. 1 1001 1001 80310904 Feb  8 12:49 node

The output to the command which yarn

/tools/nodejs/node-v16.14.0-linux-x64/bin/yarn

Everything seems fine to me and yet the error is still happening

Strangely, when i wrote a sample job, it works well

pipeline {
  agent none
  stages {
    stage('NodeJS Build') {
      agent {
        node { label 'docker-nodejs-slave' }
      }
      steps {
        script {
          env.NPM_AUTH_KEY = ' '
          env.NPM_EMAIL = ' '
          sh '''
            export NODEJS_VERSION=16
            source /etc/profile.d/jenkins.sh
            npm -v
            node -v
            yarn typecheck;
          '''
        }
      }
    }
  }
}

Output:

+npm -v
8.3.1
+node -v
v16.14.0
+yarn typecheck
yarn run v1.22.17
$ tsc --noEmit
Done in 17.01s.
+yarn prettier:check
yarn run v1.22.17
$ prettier -l 'src/**/*.{js,ts,tsx}'
Done in 7.18s.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS

but why it is not working in my API Jenkins pipeline using shared library is a big question, i am using the same slave for both, i am missing something in the declarative pipeline, kindly help me with this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2025-02-12 07:29:43

尝试在SH块之前定义路径变量。请参阅以下管道语法。 PATH+NODEHOME将附加到路径变量的定义路径。这里的Nodehome只是提高可读性的字符串。

withEnv(['PATH+NODEHOME=/tools/nodejs/node-v16-linux-x64/bin']) {
          echo "PATH is: $PATH"
          sh '''
           which yarn
           <YOUR Commands>
          '''
        }

Try defining PATH variable before the sh block. Refer to the following pipeline syntax. PATH+NODEHOME will append the defined path to the PATH variable. Here NODEHOME is just a string to improve readability.

withEnv(['PATH+NODEHOME=/tools/nodejs/node-v16-linux-x64/bin']) {
          echo "PATH is: $PATH"
          sh '''
           which yarn
           <YOUR Commands>
          '''
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文