Answers: <p>It sounds like the issue is related to the <strong>PATH</strong> environment variable not being set correctly for the kubectl krew command.</p>
  <ul>
  <li>Set the <strong>PATH</strong> in the Pipeline Script
  <pre><code>environment {
      PATH = &quot;${env.PATH}:${env.HOME}/.krew/bin&quot;
  }
  </code></pre>
  </li>
  <li>Use the <strong>withEnv</strong> Step
  <pre><code>script {
      withEnv([&quot;PATH=${env.PATH}:${env.HOME}/.krew/bin&quot;]) {
          sh 'kubectl krew install hlf'
      }
  }
  </code></pre>
  </li>
  <li>Update the <strong>Node Configuration</strong>
  <strong>Manage Jenkins &gt; Manage Nodes and Clouds. &gt; Your Node &gt; Configure &gt; Node Properties &gt; Environment Variables</strong>
  <pre><code>PATH = &quot;${env.PATH}:${env.HOME}/.krew/bin&quot;
  </code></pre>
  </li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2024-08-16T16:46:42.190Z
Answers: 2024-08-16T17:43:03.153Z
Answers: 2024-08-16T17:43:03.153Z
Answers: YassineLbk
Body: <p>I'm new to jenkins . I have written a jenkins pipeline to create blockchain network using HLF Operator.
  I've installed kubectl on the vm and used it as node in jenkins.
  The kubectl commands and other work fine but I'm facing issues when it comes to krew.</p>
  <p>If I run the pipeline stages steps with</p>
  <pre><code> stage('Install Krew HLF'){
      steps{
          script{
              sh 'export PATH=&quot;${KREW_ROOT:-$HOME/.krew}/bin:$PATH&quot; &amp;&amp; kubectl krew install hlf '
          }
      }
  </code></pre>
  <p>But when I use the command without the export part , it fails.</p>
  <p>How am I supposed to tackle this.</p>
  
Comments: CC BY-SA 4.0
Comments: 2024-02-22T14:32:21.333Z
Comments: This got resolved . The issue was with the path variable . I made these changes in my pipeline.  environment{
          PATH = "${PATH}:/home/xyz/.krew/bin"
      }
Comments: Haaris Khatri
Tags: <kubernetes><jenkins><jenkins-pipeline><cicd>
Title: How to work with krew in Jenkins?
UserDisplayName: Haaris Khatri
ThreadText: # How to work with krew in Jenkins?
  
  (Asked by: username_0 on 2024-02-21)
  
  I'm new to jenkins . I have written a jenkins pipeline to create blockchain network using HLF Operator.
  I've installed kubectl on the vm and used it as node in jenkins.
  The kubectl commands and other work fine but I'm facing issues when it comes to krew.
  
  If I run the pipeline stages steps with
  
  ```
   stage('Install Krew HLF'){
      steps{
          script{
              sh 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" && kubectl krew install hlf '
          }
      }
  
  ```
  
  But when I use the command without the export part , it fails.
  
  How am I supposed to tackle this.
  
  **Tags:** kubernetes, jenkins, jenkins-pipeline, cicd
  
  > **Comments:**
  > **username_0**: This got resolved . The issue was with the path variable . I made these changes in my pipeline.  environment{         PATH = "${PATH}:/home/xyz/.krew/bin"     }  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-08-16. Score: 1
  
  It sounds like the issue is related to the **PATH** environment variable not being set correctly for the kubectl krew command.
  
  * Set the **PATH** in the Pipeline Script
  
    ```
    environment {
        PATH = "${env.PATH}:${env.HOME}/.krew/bin"
    }
  
    ```
  * Use the **withEnv** Step
  
    ```
    script {
        withEnv(["PATH=${env.PATH}:${env.HOME}/.krew/bin"]) {
            sh 'kubectl krew install hlf'
        }
    }
  
    ```
  * Update the **Node Configuration**
    **Manage Jenkins > Manage Nodes and Clouds. > Your Node > Configure > Node Properties > Environment Variables**
  
    ```
    PATH = "${env.PATH}:${env.HOME}/.krew/bin"
  
    ```
  
  
  ---
  
  