[JIRA] (JENKINS-60547) KubernetesDeclarativeAgent workingDir is ignored in templating Jenkins agent pod

3 views
Skip to first unread message

afeller@bandwidth.com (JIRA)

unread,
Dec 19, 2019, 12:53:02 PM12/19/19
to jenkinsc...@googlegroups.com
Andrew Feller created an issue
 
Jenkins / Bug JENKINS-60547
KubernetesDeclarativeAgent workingDir is ignored in templating Jenkins agent pod
Issue Type: Bug Bug
Assignee: Unassigned
Components: kubernetes-plugin
Created: 2019-12-19 17:52
Environment: Jenkins core 2.176.4

ace-editor:1.1
analysis-core:1.96
ant:1.10
antisamy-markup-formatter:1.6
apache-httpcomponents-client-4-api:4.5.10-2.0
artifactory:3.4.1
atlassian-jira-software-cloud:1.0.4
authentication-tokens:1.3
blueocean:1.21.0
blueocean-autofavorite:1.2.4
blueocean-bitbucket-pipeline:1.21.0
blueocean-commons:1.21.0
blueocean-config:1.21.0
blueocean-core-js:1.21.0
blueocean-dashboard:1.21.0
blueocean-display-url:2.3.0
blueocean-events:1.21.0
blueocean-git-pipeline:1.21.0
blueocean-github-pipeline:1.21.0
blueocean-i18n:1.21.0
blueocean-jira:1.21.0
blueocean-jwt:1.21.0
blueocean-personalization:1.21.0
blueocean-pipeline-api-impl:1.21.0
blueocean-pipeline-editor:1.21.0
blueocean-pipeline-scm-api:1.21.0
blueocean-rest:1.21.0
blueocean-rest-impl:1.21.0
blueocean-web:1.21.0
bouncycastle-api:2.17
branch-api:2.5.5
build-monitor-plugin:1.12+build.201809061734
checkstyle:4.0.0
cloudbees-bitbucket-branch-source:2.6.0
cloudbees-folder:6.10.0
command-launcher:1.4
compress-buildlog:1.2
conditional-buildstep:1.3.6
config-file-provider:3.6.2
credentials:2.3.0
credentials-binding:1.20
dashboard-view:2.12
display-url-api:2.3.2
docker-commons:1.15
docker-workflow:1.21
durable-task:1.33
external-monitor-job:1.7
favorite:2.3.2
gatling:1.2.7
git:4.0.0
git-client:3.0.0
git-server:1.9
github:1.29.5
github-api:1.95
github-branch-source:2.5.8
github-organization-folder:1.6
gradle:1.35
greenballs:1.15
handlebars:1.1.1
handy-uri-templates-2-api:2.1.8-1.0
htmlpublisher:1.21
http_request:1.8.24
icon-shim:2.0.3
ivy:2.1
jackson2-api:2.10.1
jacoco:3.0.4
javadoc:1.5
jaxb:2.3.0.1
jdk-tool:1.4
jenkins-design-language:1.21.0
jira:3.0.11
jira-steps:1.5.1
job-dsl:1.76
jquery:1.12.4-1
jquery-detached:1.2.1
jsch:0.1.55.1
junit:1.28
kubernetes:1.19.3
kubernetes-client-api:4.6.4-1
kubernetes-credentials:0.4.1
ldap:1.21
lockable-resources:2.7
mailer:1.29
managed-scripts:1.4
mapdb-api:1.0.9.0
matrix-auth:2.5
matrix-project:1.14
maven-plugin:3.4
mercurial:2.8
metrics:4.0.2.6
momentjs:1.1.1
multiple-scms:0.6
node-iterator-api:1.5.0
openshift-client:1.0.32
openshift-login:1.0.22
openshift-pipeline:1.0.56
openshift-sync:1.0.44
pam-auth:1.6
parameterized-scheduler:0.8
parameterized-trigger:2.36
pipeline-build-step:2.10
pipeline-github-lib:1.0
pipeline-githubnotify-step:1.0.4
pipeline-graph-analysis:1.10
pipeline-input-step:2.11
pipeline-milestone-step:1.3.1
pipeline-model-api:1.5.0
pipeline-model-declarative-agent:1.1.1
pipeline-model-definition:1.5.0
pipeline-model-extensions:1.5.0
pipeline-rest-api:2.12
pipeline-stage-step:2.3
pipeline-stage-tags-metadata:1.5.0
pipeline-stage-view:2.12
pipeline-utility-steps:2.3.1
plain-credentials:1.5
project-inheritance:19.08.02
prometheus:2.0.6
promoted-builds:3.5
pubsub-light:1.13
rebuild:1.31
run-condition:1.2
scm-api:2.6.3
script-security:1.68
slack:2.34
sse-gateway:1.20
ssh-credentials:1.17.3
ssh-slaves:1.30.2
structs:1.20
subversion:2.12.2
support-core:2.65
test-results-analyzer:0.3.5
timestamper:1.10
token-macro:2.10
variant:1.3
vsphere-cloud:2.21
windows-slaves:1.5
workflow-aggregator:2.6
workflow-api:2.38
workflow-basic-steps:2.18
workflow-cps:2.78
workflow-cps-global-lib:2.15
workflow-durable-task-step:2.35
workflow-job:2.36
workflow-multibranch:2.21
workflow-remote-loader:1.5
workflow-scm-step:2.9
workflow-step-api:2.21
workflow-support:3.3
xray-connector:2.1.2
Priority: Major Major
Reporter: Andrew Feller

While working around the changes in JENKINS-58705, I discovered the KubernetesDeclarativeAgent.workingDir attribute method of configuring the workspace-volume of the Jenkins agent is ignored as it results in the recent /home/jenkins/agent/ change.

Example Jenkinsfile demonstrating issue:

pipeline {
    agent {
        kubernetes {
            cloud 'openshift'
            label UUID.randomUUID().toString()
            workingDir '/home/jenkins'
        }
    }
    options {
        timestamps()
    }
    stages {
        stage('Greeting') {
            steps {
                script {
                    container('jnlp') {
                        sh 'echo "Hello world"'
                    }
                }
            }
        }
    }
}

Resulting console output:

[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
‘eb0a374c-d844-4327-a140-891e892cfd76-793rd-5rhhr’ is offline
Agent eb0a374c-d844-4327-a140-891e892cfd76-793rd-5rhhr is provisioned from template Kubernetes Pod Template

apiVersion: "v1"
kind: "Pod"
metadata:
annotations:
buildUrl: "http://172.24.30.67:80/job/os-demo-afeller/job/os-demo-afeller-pull-request/18/"
labels:
jenkins: "slave"
jenkins/eb0a374c-d844-4327-a140-891e892cfd76: "true"
name: "eb0a374c-d844-4327-a140-891e892cfd76-793rd-5rhhr"
spec:
containers:

  • env:
  • name: "JENKINS_SECRET"
    value: "********"
  • name: "JENKINS_TUNNEL"
    value: "172.24.221.21:50000"
  • name: "JENKINS_AGENT_NAME"
    value: "eb0a374c-d844-4327-a140-891e892cfd76-793rd-5rhhr"
  • name: "JENKINS_NAME"
    value: "eb0a374c-d844-4327-a140-891e892cfd76-793rd-5rhhr"
  • name: "JENKINS_AGENT_WORKDIR"
    value: "/home/jenkins/agent"
  • name: "JENKINS_URL"
    value: "http://172.24.30.67:80/"
  • name: "HOME"
    value: "/home/jenkins"
    image: "jenkins/jnlp-slave:alpine"
    name: "jnlp"
    volumeMounts:
  • mountPath: "/home/jenkins/agent"
    name: "workspace-volume"
    readOnly: false
    nodeSelector: {}
    restartPolicy: "Never"
    volumes:
  • emptyDir: {}
    name: "workspace-volume"

As the KubernetesDeclarativeAgent passes configuration to PodTemplate, I think the issue is in PodTemplate resolves the working dir.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

afeller@bandwidth.com (JIRA)

unread,
Dec 19, 2019, 2:02:03 PM12/19/19
to jenkinsc...@googlegroups.com
Andrew Feller commented on Bug JENKINS-60547
 
Re: KubernetesDeclarativeAgent workingDir is ignored in templating Jenkins agent pod

Also worth noting that hard coding the volume mount in yaml fails spectacularly

---
apiVersion: "v1"
kind: "Pod"
metadata:
  labels:
    jenkins: "slave"
    jenkins/os-demo-6a49dcb7-3b17-4415-aa59-ea9a7fe2783f: "true"
  name: "os-demo-6a49dcb7-3b17-4415-aa59-ea9a7fe2783f-80z3r-ncjrp"
spec:
  containers:
  - env:
    - name: "JENKINS_SECRET"
      value: "********"
    - name: "JENKINS_TUNNEL"
      value: "172.24.221.21:50000"
    - name: "JENKINS_AGENT_NAME"
      value: "os-demo-6a49dcb7-3b17-4415-aa59-ea9a7fe2783f-80z3r-ncjrp"
    - name: "JENKINS_NAME"
      value: "os-demo-6a49dcb7-3b17-4415-aa59-ea9a7fe2783f-80z3r-ncjrp"
    - name: "JENKINS_AGENT_WORKDIR"
      value: "/home/jenkins/agent"
    - name: "JENKINS_URL"
      value: "http://172.24.30.67:80/"
    - name: "HOME"
      value: "/home/jenkins"
    image: "openshift/jenkins-slave-base-centos7:v3.11"
    name: "jnlp"
    resources:
      limits:
        cpu: "1.0"
        memory: "1Gi"
      requests:
        cpu: "0.1"
        memory: "0Mi"
    volumeMounts:
    - mountPath: "/home/jenkins"
      name: "workspace-volume"
      readOnly: false
    - mountPath: "/home/jenkins/agent"
      name: "workspace-volume"
      readOnly: false
  imagePullSecrets:
  - name: ...
  nodeSelector: {}
  restartPolicy: "Never"
  serviceAccountName: "jenkins"
  volumes:
  - emptyDir: {}
    name: "workspace-volume"

afeller@bandwidth.com (JIRA)

unread,
Dec 23, 2019, 2:28:02 PM12/23/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages