jenkins pod 找不到自己的本地程序
jenkins pod cannot find its own local programs
我让 Jenkins 使用 kubernetes 创建临时 pods。
最近我想构建 .net
解决方案,所以我构建了一个自定义图像以将 .netSDK
注入我的 pod。
FROM jenkins/inbound-agent
USER root
RUN apt-get update;
RUN apt install wget
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
RUN apt-get install -y apt-transport-https && \
apt-get update && \
apt-get install -y dotnet-sdk-5.0
USER jenkins
我只是按照 here 中的步骤操作。
在那之后,我确保 Jenkins 在声明 pod 时会拉取这个新镜像。
然而,当我 运行 这个管道时:
pipeline {
parameters{
string(name: 'url', description: 'repository url')
string(name: 'branch', description: 'branch name')
string(name: 'agent', description: 'agent name')
}
agent { label "${params.agent}" }
stages {
stage('test') {
steps {
sh 'dotnet --info'
}
}
...
}
}
}
它抛出一条错误消息:dotnet: not found
/home/jenkins/agent/workspace/pipeline_DotnetBuild@tmp/durable-eb21aaa2/script.sh: 1:
/home/jenkins/agent/workspace/pipeline_DotnetBuild@tmp/durable-eb21aaa2/script.sh: dotnet: not found
所以我确实以 bash 模式连接到 pod 以查看发生了什么。
我可以执行:
jenkins@pod-f9xm0:~$ dotnet
Usage: dotnet [options]
Usage: dotnet [path-to-application]
…
dotnet 文件位于 usr/bin/dotnet
以及 pod 内。
所以我想知道这里发生了什么?我显然误解了一些概念。
感谢您的帮助和解释!
在尽可能接近地复制您的问题后,我得到了类似的结果。
使用 sh 'dotnet --info'
从脚本启动 dotnet 会引发错误
jenkins@157d7dfc5949:~$ cat test.sh
sh 'dotnet --info'
jenkins@157d7dfc5949:~$ ./test.sh
sh: 0: Can't open dotnet --info
用 /bin/bash -c dotnet --info
替换 sh 'dotnet --info'
解决了这个问题。
jenkins@157d7dfc5949:~$ cat test.sh
/bin/bash -c dotnet --info
jenkins@157d7dfc5949:~$ ./test.sh
Usage: dotnet [options]
Usage: dotnet [path-to-application]
Options:
-h|--help Display help.
--info Display .NET information.
--list-sdks Display the installed SDKs.
--list-runtimes Display the installed runtimes.
path-to-application:
The path to an application .dll file to execute.
我让 Jenkins 使用 kubernetes 创建临时 pods。
最近我想构建 .net
解决方案,所以我构建了一个自定义图像以将 .netSDK
注入我的 pod。
FROM jenkins/inbound-agent
USER root
RUN apt-get update;
RUN apt install wget
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
RUN apt-get install -y apt-transport-https && \
apt-get update && \
apt-get install -y dotnet-sdk-5.0
USER jenkins
我只是按照 here 中的步骤操作。
在那之后,我确保 Jenkins 在声明 pod 时会拉取这个新镜像。 然而,当我 运行 这个管道时:
pipeline {
parameters{
string(name: 'url', description: 'repository url')
string(name: 'branch', description: 'branch name')
string(name: 'agent', description: 'agent name')
}
agent { label "${params.agent}" }
stages {
stage('test') {
steps {
sh 'dotnet --info'
}
}
...
}
}
}
它抛出一条错误消息:dotnet: not found
/home/jenkins/agent/workspace/pipeline_DotnetBuild@tmp/durable-eb21aaa2/script.sh: 1:
/home/jenkins/agent/workspace/pipeline_DotnetBuild@tmp/durable-eb21aaa2/script.sh: dotnet: not found
所以我确实以 bash 模式连接到 pod 以查看发生了什么。
我可以执行:
jenkins@pod-f9xm0:~$ dotnet
Usage: dotnet [options]
Usage: dotnet [path-to-application]
…
dotnet 文件位于 usr/bin/dotnet
以及 pod 内。
所以我想知道这里发生了什么?我显然误解了一些概念。
感谢您的帮助和解释!
在尽可能接近地复制您的问题后,我得到了类似的结果。
使用 sh 'dotnet --info'
从脚本启动 dotnet 会引发错误
jenkins@157d7dfc5949:~$ cat test.sh
sh 'dotnet --info'
jenkins@157d7dfc5949:~$ ./test.sh
sh: 0: Can't open dotnet --info
用 /bin/bash -c dotnet --info
替换 sh 'dotnet --info'
解决了这个问题。
jenkins@157d7dfc5949:~$ cat test.sh
/bin/bash -c dotnet --info
jenkins@157d7dfc5949:~$ ./test.sh
Usage: dotnet [options]
Usage: dotnet [path-to-application]
Options:
-h|--help Display help.
--info Display .NET information.
--list-sdks Display the installed SDKs.
--list-runtimes Display the installed runtimes.
path-to-application:
The path to an application .dll file to execute.