gpt4 book ai didi

Jenkins 管道: Executing a shell script

转载 作者:行者123 更新时间:2023-12-02 21:06:52 25 4
gpt4 key购买 nike

我已经创建了如下所示的管道,请注意,我在 Jenkinsfile 所在的源代码存储库中拥有脚本文件,即“backup_grafana.sh”和“gitPush.sh”。但由于以下错误,我无法执行该脚本:-

/home/jenkins/workspace/grafana-backup@tmp/durable-52495dad/script.sh: 
line 1: backup_grafana.sh: not found

请注意,我正在 pod 中的 kubernetes 上运行 jenkins master。因此,按照错误建议复制脚本文件是不可能的,因为 Pod 可能会被销毁并动态重新创建(在这种情况下,使用新的 Pod,我的脚本将不再在 jenkins master 中可用)

pipeline {
agent {
node {
label 'jenkins-slave-python2.7'
}
}
stages {
stage('Take the grafana backup') {
steps {
sh 'backup_grafana.sh'
}
}
stage('Push to the grafana-backup submodule repository') {
steps {
sh 'gitPush.sh'
}
}
}
}

您能否建议我如何在 Jenkinsfile 中运行这些脚本?我还想提一下,我想在我已经精心创建的 python 从机上运行这些脚本。

最佳答案

如果命令“sh backup_grafana.sh”在实际应该成功执行时未能执行,这里有两种可能的解决方案。

1) 也许您需要在这些可执行命令前面加一个点斜杠来告诉 shell 它们的位置。如果它们不在您的 $PATH 中,您需要告诉 shell 可以在当前目录中找到它们。这是添加了四个非空白字符的固定 Jenkinsfile:

pipeline {
agent {
node {
label 'jenkins-slave-python2.7'
}
}
stages {
stage('Take the grafana backup') {
steps {
sh './backup_grafana.sh'
}
}
stage('Push to the grafana-backup submodule repository') {
steps {
sh './gitPush.sh'
}
}
}
}

2) 通过将以下内容之一声明为脚本中的第一行,检查您是否已将文件声明为 bash 或 sh 脚本:

#!/bin/bash 

#!/bin/sh

关于 Jenkins 管道: Executing a shell script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44716605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com