在kubernetes群集上执行的Jenkins作业在jnlp映像而不是指定映像上运行

2q5ifsrm  于 2023-01-16  发布在  Jenkins
关注(0)|答案(1)|浏览(160)

我遇到了一个我不太明白的情况,我的代码似乎在错误的映像中执行--尽管日志声明它已经加载了我的映像。

预期输出与实际输出

当我运行docker run -it jstevnsvig/jenkins-build-slave-php:v8.2 /bin/sh -c "dpkg-query -l | cat"时,我得到了预期的输出。
当我使用适当的标记运行Jenkins自由式作业时,通过执行dpkg-query -l | cat的单个脚本步骤,我得到了我认为是在jnlp映像(jenkins/inbound-agent:3077.vd69cf116da_6f-3-jdk11)中运行的输出。如何使它在正确的映像上运行?

Jenkins Kubernetes云Pod模板配置

Jenkins作业控制台

Started by user JoSSte
Running as SYSTEM
Agent php8-2dfd8 is provisioned from template php8
---
apiVersion: "v1"
kind: "Pod"
metadata:
  labels:
    jenkins: "slave"
    jenkins/label-digest: "cb0616020c016c081bd72366740b4151da57f6a3"
    jenkins/label: "php8"
  name: "php8-2dfd8"
  namespace: "devops-tools"
spec:
  containers:
  - args:
    - "9999999"
    command:
    - "sleep"
    image: "jstevnsvig/jenkins-build-slave-php:v8.2"
    imagePullPolicy: "IfNotPresent"
    name: "php8t"
    resources: {}
    tty: false
    volumeMounts:
    - mountPath: "/home/jenkins/agent"
      name: "workspace-volume"
      readOnly: false
    workingDir: "/home/jenkins/agent"
  - env:
    - name: "JENKINS_PROTOCOLS"
      value: "JNLP4-connect"
    - name: "JENKINS_SECRET"
      value: "********"
    - name: "JENKINS_AGENT_NAME"
      value: "php8-2dfd8"
    - name: "JENKINS_DIRECT_CONNECTION"
      value: "jenkins-service:50000"
    - name: "JENKINS_INSTANCE_IDENTITY"
      value: "..."
    - name: "JENKINS_NAME"
      value: "php8-2dfd8"
    - name: "JENKINS_AGENT_WORKDIR"
      value: "/home/jenkins/agent"
    image: "jenkins/inbound-agent:3077.vd69cf116da_6f-3-jdk11"
    name: "jnlp"
    resources:
      requests:
        memory: "256Mi"
        cpu: "100m"
    volumeMounts:
    - mountPath: "/home/jenkins/agent"
      name: "workspace-volume"
      readOnly: false
  hostNetwork: false
  nodeSelector:
    kubernetes.io/os: "linux"
  restartPolicy: "Never"
  volumes:
  - emptyDir:
      medium: ""
    name: "workspace-volume"

我尝试将容器模板的标签更改为jnlp,但它无法正确连接(我的映像构建在jenkins/agent映像上)

q5lcpyga

q5lcpyga1#

如本文所述,默认情况下,Jenkins代理中的命令将在jnlp容器中运行。如果您希望在podTemplate中定义的另一个容器中运行这些命令,请使用container {..}块(此处的部分)

podTemplate(containers: [
    containerTemplate(name: 'maven', image: 'maven:3.8.1-jdk-8', command: 'sleep', args: '99d'),
    containerTemplate(name: 'golang', image: 'golang:1.16.5', command: 'sleep', args: '99d')
  ]) {

    node(POD_LABEL) {
        stage('Get a Maven project') {
            git 'https://github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage('Build a Maven project') {
                    sh 'mvn -B -ntp clean install'
                }
            }
        }
...

相关问题