jenkinsci / docker-plugin

Jenkins cloud plugin that uses Docker
https://plugins.jenkins.io/docker-plugin/
MIT License
486 stars 322 forks source link

Docker.inside() sh block doesn't wait until "$@" is executed #1057

Closed studioj closed 3 months ago

studioj commented 3 months ago

Jenkins and plugins versions report

JenkinsVersion ```text Jenkins 2.414.3 ```
Environment ```text Parameterized-Remote-Trigger:3.2.0 PrioritySorter:5.0.0 ace-editor:1.1 active-directory:2.33 all-changes:1.5 ansicolor:1.0.4 ant:497.v94e7d9fffa_b_9 antisamy-markup-formatter:162.v0e6ec0fcfcf6 any-buildstep:14.ve115ec1484f0 apache-httpcomponents-client-4-api:4.5.14-208.v438351942757 authentication-tokens:1.53.v1c90fd9191a_b_ backup:1.6.1 badge:1.9.1 basic-branch-build-strategies:81.v05e333931c7d batch-task:1.19 bitbucket:223.vd12f2bca5430 bitbucket-build-status-notifier:1.4.2 bitbucket-pullrequest-builder:1.5.0 blame-upstream-commiters:1.2 blueocean:1.27.8 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.27.8 blueocean-commons:1.27.8 blueocean-config:1.27.8 blueocean-core-js:1.27.8 blueocean-dashboard:1.27.8 blueocean-display-url:2.4.2 blueocean-events:1.27.8 blueocean-executor-info:1.27.8 blueocean-git-pipeline:1.27.8 blueocean-github-pipeline:1.27.8 blueocean-i18n:1.27.8 blueocean-jira:1.27.8 blueocean-jwt:1.27.8 blueocean-personalization:1.27.8 blueocean-pipeline-api-impl:1.27.8 blueocean-pipeline-editor:1.27.8 blueocean-pipeline-scm-api:1.27.8 blueocean-rest:1.27.8 blueocean-rest-impl:1.27.8 blueocean-web:1.27.8 bootstrap4-api:4.6.0-6 bootstrap5-api:5.3.2-2 bouncycastle-api:2.29 branch-api:2.1128.v717130d4f816 build-cause-run-condition:0.1 build-monitor-plugin:1.14-745.ve2023a_305f40 build-name-setter:2.4.0 build-pipeline-plugin:1.5.8 build-timeout:1.31 build-token-root:151.va_e52fe3215fc build-user-vars-plugin:1.9 built-on-column:1.4 caffeine-api:3.1.8-133.v17b_1ff2e0599 changes-since-last-success:0.6 checks-api:2.0.2 cloudbees-bitbucket-branch-source:848.v42c6a_317eda_e cloudbees-folder:6.858.v898218f3609d code-coverage-api:4.99.0 command-launcher:107.v773860566e2e commons-httpclient3-api:3.1-3 commons-lang3-api:3.13.0-62.v7d18e55f51e2 commons-text-api:1.10.0-78.v3e7b_ea_d5a_fe1 conditional-buildstep:1.4.3 console-column-plugin:197.vcf5a_ec1d7b_47 convert-to-pipeline:1.0 copyartifact:722.v0662a_9b_e22a_c coverage:1.2.0 credentials:1293.vff276f713473 credentials-binding:636.v55f1275c7b_27 cvs:2.19.1 dashboard-view:2.495.v07e81500c3f2 data-tables-api:1.13.6-5 delivery-pipeline-plugin:1.4.2 disk-usage:1.2 display-url-api:2.200.vb_9327d658781 distTest:1.0 docker-commons:439.va_3cb_0a_6a_fb_29 docker-workflow:572.v950f58993843 downstream-buildview:69.v16da_b_2c36f6c dtkit-api:3.0.2 durable-task:523.va_a_22cf15d5e0 echarts-api:5.4.0-7 email-ext:2.102 envinject:2.908.v66a_774b_31d93 envinject-api:1.199.v3ce31253ed13 extended-choice-parameter:376.v2e02857547b_a_ external-monitor-job:215.v2e88e894db_f8 favorite:2.4.3 file-operations:177.vd1773063d935 flexible-publish:0.16.1 font-awesome-api:6.4.2-1 forensics-api:2.3.0 git:5.2.0 git-client:4.5.0 git-server:99.va_0826a_b_cdfa_d github:1.37.3 github-api:1.316-451.v15738eef3414 github-branch-source:1741.va_3028eb_9fd21 global-post-script:1.1.4 greenballs:1.15.1 groovy:457.v99900cb_85593 groovy-label-assignment:1.2.0 groovy-postbuild:2.5 groovy-remote:0.2 handlebars:3.0.8 handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953 hashicorp-vault-plugin:361.v44fea_4fc08d9 htmlpublisher:1.32 http_request:1.15 hudson-pview-plugin:1.8 image-gallery:2.0.2 instance-identity:173.va_37c494ec4e5 ionicons-api:56.v1b_1c8c49374e jackson2-api:2.15.3-366.vfe8d1fa_f8c87 jakarta-activation-api:2.0.1-3 jakarta-mail-api:2.0.1-3 javadoc:243.vb_b_503b_b_45537 javax-activation-api:1.2.0-6 javax-mail-api:1.6.2-9 jaxb:2.3.9-1 jdk-tool:73.vddf737284550 jenkins-design-language:1.27.8 jenkins-multijob-plugin:623.v03401733c9a_9 jersey2-api:2.41-133.va_03323b_a_1396 jira:3.11 jjwt-api:0.11.5-77.v646c772fddb_0 job-import-plugin:3.6 join:1.21 jquery:1.12.4-1 jquery-detached:1.2.1 jquery-ui:1.0.2 jquery3-api:3.7.1-1 jsch:0.2.8-65.v052c39de79b_2 junit:1240.vf9529b_881428 last-changes:2.7.11 lastsuccessversioncolumn:1.1 ldap:701.vf8619de9160a_ ldapemail:0.8 leastload:3.0.0 lockable-resources:1185.v0c528656ce04 log-parser:2.3.1 mailer:463.vedf8358e006b_ mapdb-api:1.0.9-28.vf251ce40855d matrix-auth:3.1.10 matrix-project:818.v7eb_e657db_924 matrix-reloaded:1.1.3 matrixtieparent:1.2 maven-plugin:3.23 measurement-plots:0.1 mercurial:1260.vdfb_723cdcc81 metrics:4.2.18-442.v02e107157925 mina-sshd-api-common:2.11.0-86.v836f585d47fa_ mina-sshd-api-core:2.11.0-86.v836f585d47fa_ momentjs:1.1.1 monitoring:1.95.0 multi-slave-config-plugin:1.2.0 multiple-scms:0.8 naginator:1.421.v85c11e2db_507 nodelabelparameter:1.12.0 nunit:442.v157a_e8448a_d7 okhttp-api:4.11.0-157.v6852a_a_fa_ec11 pam-auth:1.10 parameterized-trigger:2.46 perfpublisher:8.09 permissive-script-security:0.7 pipeline-build-step:505.v5f0844d8d126 pipeline-graph-analysis:202.va_d268e64deb_3 pipeline-graph-view:202.v6da_a_9e590325 pipeline-groovy-lib:689.veec561a_dee13 pipeline-input-step:477.v339683a_8d55e pipeline-milestone-step:111.v449306f708b_7 pipeline-model-api:2.2144.v077a_d1928a_40 pipeline-model-definition:2.2144.v077a_d1928a_40 pipeline-model-extensions:2.2144.v077a_d1928a_40 pipeline-rest-api:2.33 pipeline-stage-step:305.ve96d0205c1c6 pipeline-stage-tags-metadata:2.2144.v077a_d1928a_40 pipeline-stage-view:2.33 plain-credentials:143.v1b_df8b_d3b_e48 plot:2.1.12 plugin-util-api:3.6.0 popper-api:1.16.1-3 popper2-api:2.11.6-4 postbuild-task:1.9 postbuildscript:2.11.0 powershell:2.1 prism-api:1.29.0-8 progress-bar-column-plugin:11.vdef198c2d6c1 project-health-report:1.2 publish-over:0.22 pubsub-light:1.18 pwauth:0.4 pyenv-pipeline:2.1.2 python:1.3 random-string-parameter:1.0 resource-disposer:0.23 run-condition:1.7 run-condition-extras:0.3 saml:4.429.v9a_781a_61f1da_ schedule-build:502.v9379e178e65b_ scm-api:676.v886669a_199a_a_ script-security:1275.v23895f409fb_d slave-setup:1.16 slave-squatter:1.2 slave-status:56.v1798df8ff586 snakeyaml-api:2.2-111.vc6598e30cc65 sonar:2.16.1 sse-gateway:1.26 ssh:2.6.1 ssh-credentials:308.ve4497b_ccd8f4 ssh-slaves:2.916.vd17b_43357ce4 sshd:3.312.v1c601b_c83b_0e structs:325.vcb_307d2a_2782 subversion:2.17.3 terminal:1.4 terminate-ssh-processes-plugin:1.0 test-results-analyzer:0.4.0 thinBackup:1.18 throttle-concurrents:2.14 timestamper:1.26 token-macro:384.vf35b_f26814ec trilead-api:2.84.v72119de229b_7 uno-choice:2.8.0 variant:60.v7290fc0eb_b_cd versionnumber:1.11 windows-slaves:1.8.1 workflow-aggregator:596.v8c21c963d92d workflow-api:1283.v99c10937efcb_ workflow-basic-steps:1042.ve7b_140c4a_e0c workflow-cps:3805.v769b_b_74b_db_14 workflow-cps-global-lib:609.vd95673f149b_b workflow-durable-task-step:1289.v4d3e7b_01546b_ workflow-job:1348.v32a_a_f150910e workflow-multibranch:756.v891d88f2cd46 workflow-scm-step:415.v434365564324 workflow-step-api:639.v6eca_cd8c04a_a_ workflow-support:865.v43e78cc44e0d ws-cleanup:0.45 xshell:203.v80a_c62d7886f xunit:3.1.3 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

JenkinsOS ```text Ubuntu 18 ```
SlaveOS ```text Ubuntu 18 ```

Reproduction steps

DockerFile add this into your dockerfile ```text ENTRYPOINT [ "/tmp/entry.sh" ] ```
/tmp/entry.sh ```text sleep 60 touch /tmp/sleepingIsDone exec "$@" ```
JenkinsFile which fails ```text notWaitingDocker = docker.build("not-waiting-docker:latest", '-f Dockerfile .') notWaitingDocker.inside() { sh ''' ps -au cat /tmp/sleepingIsDone ''' } ```
JenkinsFile which passes ```text notWaitingDocker = docker.build("not-waiting-docker:latest", '-f Dockerfile .') notWaitingDocker.inside() { sh ''' ps -au sleep 120 cat /tmp/sleepingIsDone ''' } ```

Expected Results

As far as I understand or can read here https://github.com/jenkinsci/docker-plugin?tab=readme-ov-file#note-on-entrypoint it seems to be the intention to have the entry point complete before docker exec starts sending the contents of the sh block

so connecting to the above case I expect /tmp/sleepingIsDone to be there when i run the sh block

Actual Results

no such file /tmp/sleepingIsDone

Anything else?

some extra side info would be useful, maybe there are timeouts in place which i don't know about, maybe there are workarounds in place which don't require me to update many jenkinsfiles using my docker image.

any extra info is helpful. Great thanks for this nice plugin

Are you interested in contributing a fix?

No response