【问题标题】:jenkins pod cannot find its own local programsjenkins pod 找不到自己的本地程序
【发布时间】:2021-10-02 20:43:42
【问题描述】:

我让 Jenkins 使用 kubernetes 创建临时 pod。 最近我想构建.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 内。

所以我想知道这里发生了什么?我显然误解了一些概念。

感谢您的帮助和解释!

【问题讨论】:

  • 为了让多个用户可以在系统范围内访问二进制文件,管理员应该将它放到 /usr/local/bin 中
  • 奇怪,和你说的不太相符:unix.stackexchange.com/questions/8656/… 还是我错过了阅读
  • 我确实在 dockerfile 中添加了这个命令: RUN cp /usr/bin/dotnet /usr/local/bin 但仍然是相同的行为

标签: jenkins kubernetes kubernetes-pod


【解决方案1】:

在尽可能地复制您的问题后,我得到了类似的结果。

使用 sh 'dotnet --info' 从脚本启动 dotnet 会引发错误

jenkins@157d7dfc5949:~$ cat test.sh 
sh 'dotnet --info'
jenkins@157d7dfc5949:~$ ./test.sh 
sh: 0: Can't open dotnet --info

sh 'dotnet --info' 替换为/bin/bash -c 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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2017-08-31
    • 2019-02-20
    • 1970-01-01
    • 2021-03-19
    • 2019-10-25
    • 1970-01-01
    相关资源
    最近更新 更多