卷在Kubernetes代理Jenkins

lsmd5eda  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(222)

我有一个使用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
"""
        }
    }

错误消息为“curl.... /home/jenkins/agent/ng-cleaner@tmp/durable-0 d154 ecf/script.sh:2:curl:未找到”
我尝试过:
1.在主“构建”容器中添加了shell步骤:shell:sh“apk add --no-cache curl”,也尝试了“apt install curl”--没有帮助
1.添加了带有 curl 图像的新容器:- 名称: curl 图像: curl / curl :7.83.1 tty已启用:true tty:true命令:- -猫--也没什么帮助
有什么建议吗?

vmpqdwk3

vmpqdwk31#

我解决了这个问题。需要在主容器中添加shell步骤:

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

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

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

相关问题