3

I'm running Jenkins on Kubernetes with the git plugin installed. Now I want to use git commands in my script, which fails with the log:

script.sh: line 1: git: not found

My script:

stage('Package Helm Chart'){
            sh """ 
              #!/bin/bash

              echo "Pushing to remote Repository.."

              git checkout master

              git add <myfilehere>

              git commit -m "[Jenkins] Adding Artifact ${env.BUILD_NUMBER} to repository"

              git push

              echo "Successfully pushed artifact to repository"
            """

Any idea on how to fix this?

Cheers Jst

1
  • does the git plugin actually install git or just make an installed git available to jenkins? so maybe you need to install git seperately Commented Jan 18, 2018 at 10:22

3 Answers 3

5

The sh command in question should run on a jenkins node inside a node block. This command will then run in a shell on that node. To use git in the sh tag of a pipeline script you need to have git installed and on the PATH on the node that you want to use.

If you are using Kubernetes, then I assume you are running the Jenkins master or the node from a docker image, thus this image will need git installed and on the PATH.

Once this is done the shell will be able to find git.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure but I think you mix Jenkins git plugin, that allow you to choose git as source code management for project workspace Inside project configuration, and git in command line Inside a script that which requires that git is install and present in $PATH when script is execute.

Comments

-1

In my case it was caused by unintentional error in the groovy code, i had written sh while i actually want to write echo for debugging purpose, removed it and Jenkins job ran successfully.

stage("Deploy"){
  steps{
    ----
    //sh "Deployment successful" - this resulted in script.sh: git not found error
    echo "Deployment successful" - this fixed it.
  }
}

strange but true... this could help someone who might be doing same mistake as that of mine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.