在 Jenkins 中使用 Git 命令:找不到 git

JSt*_*JSt 3 git jenkins kubernetes

我正在 Kubernetes 上运行 Jenkins,并安装了 git 插件。现在我想在我的脚本中使用 git 命令,该命令失败并显示日志:

script.sh: line 1: git: not found
Run Code Online (Sandbox Code Playgroud)

我的脚本:

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"
            """
Run Code Online (Sandbox Code Playgroud)

知道如何解决这个问题吗?

干杯Jst

Jam*_*esD 5

有问题的 sh 命令应该在节点块内的 jenkins 节点上运行。然后,该命令将在该节点上的 shell 中运行。要在管道脚本的 sh 标签中使用 git,您需要在要使用的节点上的 PATH 上安装 git。

如果您使用 Kubernetes,那么我假设您正在运行 Jenkins master 或来自 docker 映像的节点,因此该映像需要安装 git 并位于 PATH 上。

完成此操作后,shell 将能够找到 git。