jenkinsci / npm-yarn-wrapper-steps-plugin

A Jenkins plugin for convenient usage of npm and yarn in pipelines
https://plugins.jenkins.io/npm-yarn-wrapper-steps/
MIT License
2 stars 2 forks source link

Cannot use yarn from 'sh' step #15

Open reda-alaoui opened 2 years ago

reda-alaoui commented 2 years ago

Jenkins and plugins versions report

Environment ```text OS: Linux - 5.10.0-0.bpo.5-amd64 --- PrioritySorter:4.1.0 ace-editor:1.1 ant:1.13 antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 authentication-tokens:1.4 authorize-project:1.4.0 blueocean:1.25.2 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.25.2 blueocean-commons:1.25.2 blueocean-config:1.25.2 blueocean-core-js:1.25.2 blueocean-dashboard:1.25.2 blueocean-display-url:2.4.1 blueocean-events:1.25.2 blueocean-git-pipeline:1.25.2 blueocean-github-pipeline:1.25.2 blueocean-i18n:1.25.2 blueocean-jira:1.25.2 blueocean-jwt:1.25.2 blueocean-personalization:1.25.2 blueocean-pipeline-api-impl:1.25.2 blueocean-pipeline-editor:1.25.2 blueocean-pipeline-scm-api:1.25.2 blueocean-rest:1.25.2 blueocean-rest-impl:1.25.2 blueocean-web:1.25.2 bootstrap4-api:4.6.0-3 bootstrap5-api:5.1.3-4 bouncycastle-api:2.25 branch-api:2.7.0 build-timeout:1.20 caffeine-api:2.9.2-29.v717aac953ff3 checks-api:1.7.2 cloudbees-bitbucket-branch-source:751.vda_24678a_f781 cloudbees-folder:6.17.0.cosium command-launcher:1.6 conditional-buildstep:1.4.1 config-file-provider:3.9.0 cosium-jenkins-plugin:1.9.4 credentials:1074.v60e6c29b_b_44b_ credentials-binding:1.27.1 custom-tools-plugin:0.8 dark-theme:156.v6cf16af6f9ef dependency-check-jenkins-plugin:5.1.2 deploy:1.16 display-url-api:2.3.5 docker-commons:1.19 docker-workflow:1.28 durable-task:493.v195aefbb0ff2 echarts-api:5.2.2-2 elastic-axis:1.4.5 email-ext:2.87 envinject:2.4.0 envinject-api:1.8 extended-choice-parameter:0.82 extensible-choice-parameter:1.8.0 external-monitor-job:191.v363d0d1efdf8 favorite:2.3.3 font-awesome-api:5.15.4-5 gerrit-code-review:0.4.7.9.cosium gerrit-trigger:2.35.2 gerrit-voter:1.0-SNAPSHOT (private-7629d2af-rhousni) git:4.10.3 git-client:3.11.0 git-parameter:0.9.15 git-push:29.v3bfa6125d686 git-server:1.10 github:1.34.1 github-api:1.301-378.v9807bd746da5 github-branch-source:2.11.4 gradle:1.38 h2-api:1.4.199 handlebars:3.0.8 handy-uri-templates-2-api:2.1.8-1.0 htmlpublisher:1.29 jackson2-api:2.13.1-246.va8a9f3eaf46a jacoco:3.3.1 javadoc:217.v905b_86277a_2a_ javax-activation-api:1.2.0-2 javax-mail-api:1.6.2-5 jaxb:2.3.0.1 jdk-tool:1.5 jenkins-design-language:1.25.2 jira:3.6 jjwt-api:0.11.2-9.c8b45b8bb173 jnr-posix-api:3.1.7-1 jobConfigHistory:2.31-rc1107.2354f08725a_8 jquery:1.12.4-1 jquery-detached:1.2.1 jquery3-api:3.6.0-2 jsch:0.1.55.2 junit:1.54 ldap:2.7 lockable-resources:2.14 mailer:408.vd726a_1130320 matrix-auth:3.0.1 matrix-project:1.20 maven-artifact-choicelistprovider:1.9.0 maven-plugin:3.16 momentjs:1.1.1 nodejs:1.5.1 nodelabelparameter:1.10.3 npm-yarn-wrapper-steps:0.3.0 okhttp-api:4.9.3-105.vb96869f8ac3a pam-auth:1.7 parameterized-trigger:2.43 pipeline-build-step:2.15 pipeline-github-lib:36.v4c01db_ca_ed16 pipeline-graph-analysis:188.v3a01e7973f2c pipeline-input-step:446.vf27b_0b_83500e pipeline-maven:3.10.0 pipeline-milestone-step:100.v60a_03cd446e1 pipeline-model-api:1.9.3 pipeline-model-definition:1.9.3 pipeline-model-extensions:1.9.3 pipeline-multibranch-defaults:2.1 pipeline-rest-api:2.21 pipeline-stage-step:291.vf0a8a7aeeb50 pipeline-stage-tags-metadata:1.9.3 pipeline-stage-view:2.21 pipeline-utility-steps:2.12.0 plain-credentials:1.8 plugin-util-api:2.13.0 popper-api:1.16.1-2 popper2-api:2.11.2-1 pubsub-light:1.16 repository-connector:2.2.0 resource-disposer:0.17 rocketchatnotifier:1.4.10.1.cosium run-condition:1.5 schedule-build:178.v32999348869c scm-api:595.vd5a_df5eb_0e39 scoring-load-balancer:1.0.1 script-security:1131.v8b_b_5eda_c328e snakeyaml-api:1.29.1 sonar:2.14 sonar-gerrit:370.vf2cf40f43d41 sonar-quality-gates:1.3.1 sse-gateway:1.25 ssh-credentials:1.19 ssh-slaves:1.33.0 sshd:3.1.0 structs:308.v852b473a2b8c test-results-analyzer:0.3.5 theme-manager:0.6 thinBackup:1.10 throttle-concurrents:2.6 timestamper:1.17 token-macro:270.v8c2ce50dc4fc toolenv:1.2 trilead-api:1.0.13 variant:1.4 windows-slaves:1.8 workflow-aggregator:2.6 workflow-api:1136.v7f5f1759dc16 workflow-basic-steps:2.24 workflow-cps:2648.va9433432b33c workflow-cps-global-lib:552.vd9cc05b8a2e1 workflow-durable-task-step:1121.va_65b_d2701486 workflow-job:1145.v7f2433caa07f workflow-multibranch:706.vd43c65dec013 workflow-scm-step:2.13 workflow-step-api:622.vb_8e7c15b_c95a_ workflow-support:813.vb_d7c3d2984a_0 ws-cleanup:0.40 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Linux

Reproduction steps

  1. Create a pipeline using withNPMWrapper with yarnEnabled: true
  2. Inside withNPMWrapper closure, calll sh 'yarn -v'

e.g.

withNPMWrapper(credentialsId: 'my-credentials', yarnEnabled: true) {
  sh 'yarn -v'
}

Expected Results

The yarn version should be printed.

Actual Results

yarn: not found

Anything else?

https://plugins.jenkins.io/nodejs/ provides a similar wrapper fully compatible with sh step. I checked their code and found https://github.com/jenkinsci/nodejs-plugin/blob/b77f31c51ab8539c503410fede795645b5ea81d8/src/main/java/jenkins/plugins/nodejs/tools/NodeJSInstallation.java#L110. They pass the NodeJS bin directory inside an environment variable named PATH+NODEJS while this plugin overrides the PATH variable.

jameslafferty commented 2 years ago

I'm curious to understand your use case better to understand if it's a feature I'd want to support. I didn't really have any intention of supporting either npm or yarn in sh steps.

I see the main value for this plug-in in being able to rely on the committed .nvmrc to manage the node version and keeping the node stuff away from the shell stuff. There are lots of options if you want to mix 'n' match, including the plug-in you mentioned, or perhaps even more straightforwardly, choosing a node capable docker image as your agent.

I've found those approaches to be a bit more finicky and a bit more hands-on for the CI/build folks than I'd really like. My experience with this plug-in (and why I wrote it) is that I spend less time explaining node to folks who don't have it as their primary focus.

jameslafferty commented 2 years ago

Relabeling this as an enhancement, as it's really a request to support a new use case. There's no indication in the documentation or design that yarn or npm are supported from an sh step via this plugin.