我在安装了 git 插件的 Kubernetes 上运行 Jenkins。 现在我想在我的脚本中使用 git 命令,它失败并显示日志:
script.sh: line 1: git: not found
我的脚本:
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"
"""
知道如何解决这个问题吗?
干杯
最佳答案
有问题的 sh 命令应该在节点 block 内的 jenkins 节点上运行。然后该命令将在该节点上的 shell 中运行。要在管道脚本的 sh 标记中使用 git,您需要安装 git 并在要使用的节点上的 PATH 上。
如果您使用的是 Kubernetes,那么我假设您正在运行 Jenkins master 或来自 docker 镜像的节点,因此该镜像需要安装 git 并位于 PATH 上。
完成此操作后,shell 将能够找到 git。
关于git - 在 Jenkins 中使用 Git 命令 : git not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48318872/