【问题标题】:Curl in Kubernetes agent on JenkinsJenkins 上 Kubernetes 代理中的 Curl
【发布时间】:2022-10-24 21:09:37
【问题描述】:

我有一个使用 curl 的脚本,该脚本应该在 Jenkins 上的 Kubernetes 代理中运行。这是我原来的代理配置:

    pipeline {
        agent {
        kubernetes {
            customWorkspace 'ng-cleaner'
            yaml """
kind: Pod
metadata:
spec:
  imagePullSecrets:
    - name: jenkins-docker
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: agentpool
                operator: In
                values:
                  - build
  schedulerName: default-scheduler
  tolerations:
    - key: type
      operator: Equal
      value: jenkins
      effect: NoSchedule
  containers:
    - name: jnlp
      env:
        - name: CONTAINER_ENV_VAR
          value: jnlp
    - name: build
      image: tixartifactory-docker.jfrog.io/baseimages/helm:helm3.2.1-helm2.16.2-kubectl.0
      ttyEnabled: true
      command:
        - cat
      tty: true
"""
        }
    }

错误消息是“卷曲...... /home/jenkins/agent/ng-cleaner@tmp/durable-0d154ecf/script.sh:2:curl:未找到”

我尝试了什么:

  1. 向主“构建”容器添加了 shell 步骤: 外壳:sh“apk add --no-cache curl”,也尝试过“apt install curl”-没有帮助
  2. 添加了带有 curl 图像的新容器: - 名称:卷曲 图片:curlimages/curl:7.83.1 ttyEnabled: 真 tty: 真 命令: - 猫 - 也没有帮助

    关于如何使它工作的任何建议?

【问题讨论】:

  • UPT:我添加了新容器 - 名称:curl 图像:curlimages/curl:7.83.1 ttyEnabled:true tty:true 命令:-cat 并将此块添加到我的管道容器('curl'){} 它似乎工作,我curl 不再有错误,但是这个新添加的容器中的进程无法启动:“进程显然从未在 /home/jenkins/agent/ng-cleaner@tmp/durable-3ff1be5d 中启动(使用 -Dorg. jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true 可能会使问题更清楚)“

标签: docker kubernetes jenkins curl


【解决方案1】:

我解决了。 需要将 shell 步骤添加到主容器:

shell: sh "apk add --no-cache curl"

然后将我的脚本放在容器块中:

stages {
    stage('MyStage') {
        steps {
            container('build'){
                script {

【讨论】:

    猜你喜欢
    • 2020-02-27
    • 2022-08-18
    • 2021-03-17
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2019-11-26
    • 2020-11-17
    • 1970-01-01
    相关资源
    最近更新 更多