jenkins pipeline plugin and sh inside a container

1,169 views
Skip to first unread message

Ludovic SMADJA

unread,
May 2, 2016, 8:35:36 AM5/2/16
to Jenkins Users
Hi everyone,

I've implemented new pipeline as code feature with a docker image as build environment.

I can do checkout, docker pull, docker run, etc. but my issue is about sh inside a docker run (via docker.inside).

My sh is executed but I don't have any console write from the sh (in my case an ANT Script). If I run the script manualy in the container, the logs are displayed on the console.

Is anything wrong in my pipeline, or do I miss something to get logs ?

Regards,

PS : Here's my pipeline and the build console (I removed some custom data)

<PIPELINE>
    
    stage 'Build'
    node('docker'){
            checkout( ...)
            buildImgName='internal/build:latest'
            
            docker.withRegistry('https://docker-registry.jalios.net/', 'docker-registry-reader-login') {
                docker.image(buildImgName).pull()
            }
            try{
                echo "start build container and execute ANT"
                buildImg.inside( " --link ${DB_ID}:db ") {
                   // Run the ant build  <<<<<<<<<<<<<<<<<  here's the missing logs >>>>>>>>>>>>>>>>
                 sh '''#!/bin/bash 
                    /tools/ant/latest/bin/ant -f /opt/build/build.xml build  2>&1'''
                }
            }
            catch(all){
                println("Exception "+all)
            }
<PIPELINE>
<CONSOLE>
Started by user Ludovic Smadja
Entering stage Build
Proceeding
[Pipeline] Allocate node : Start
Running on jdocker.jalios.net in /home/jenkins/workspace/Core/JCMS
[Pipeline] node {
[Pipeline] General Build Wrapper : Start
[Pipeline] wrap {
[Pipeline] Set environment variables : Start
[Pipeline] withEnv {
[Pipeline] Sets up Docker registry endpoint : Start
[Pipeline] withDockerRegistry {
[Pipeline] sh
00:00:31.001 [JCMS] Running shell script
00:00:59.050 Status: Downloaded newer image for docker-registry.jalios.net/internal/build:latest
[Pipeline] echo
00:02:04.944 start build container and execute ANT
[Pipeline] sh
00:02:04.960 [JCMS] Running shell script
00:02:05.223 + docker inspect -f . docker-registry.jalios.net/internal/build:latest
00:02:05.223 .
[Pipeline] Run build steps inside a Docker container : Start
00:02:05.349 $ docker run -t -d -u 5001:5001 --link f1eae2e5faaf7e5b1a62f38789eb046866275c238fcfd65589c56371b98b5719:db -w /home/jenkins/workspace/Core/JCMS -v /home/jenkins/workspace/Core/JCMS:/home/jenkins/workspace/Core/JCMS:rw -v /home/jenkins/workspace/Core/JCMS@tmp:/home/jenkins/workspace/Core/JCMS@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** docker-registry.jalios.net/internal/build:latest cat
[Pipeline] withDockerContainer {
[Pipeline] sh
00:02:05.931 [JCMS] Running shell script
00:02:06.578 Buildfile: /opt/build/build.xml

<<<<<<<<<<<<<<<<<<<<< no console logs from ANT Script >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


[Pipeline] } //withDockerContainer
[Pipeline] Run build steps inside a Docker container : End
[Pipeline] echo
00:02:16.948 Exception hudson.AbortException: script returned exit code -1
[Pipeline] step
00:02:16.956 Archiving artifacts
00:02:17.061 Recording fingerprints
[Pipeline] step
00:02:17.152 Recording test results
[Pipeline] } //wrap
[Pipeline] General Build Wrapper : End
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
ERROR: Aucun fichier de rapport de test n'a été trouvé. Erreur de configuration?
Finished: FAILURE
<CONSOLE>
-- 


Ludovic SMADJA
R&D engineer - build process and development
JALIOS SA
http://www.jalios.com

Baptiste Mathus

unread,
May 2, 2016, 3:07:09 PM5/2/16
to jenkins...@googlegroups.com
Hi,

Wild guess, did you try to not redirect stderr to stdout to see if this changes anything? Maybe something getting mangled in that mix (would be a bug then)?

sh '''#!/bin/bash /tools/ant/latest/bin/ant -f /opt/build/build.xml build  2>&1'''

My 2 cents

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/dd0d276f-6418-4d60-a659-39134ff9c92c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ludovic SMADJA

unread,
May 12, 2016, 10:39:23 AM5/12/16
to Jenkins Users, m...@batmat.net
Thanks for your answer, but that doesn't solve the problem.

After days of search, I was preparing a issue for jenkins team and I've created a simple test case with an ubuntu image.

At this moment, great surprise, I cannot reproduce the problem in my test case. Some investigation later, my build image was build on debian:strech image. I''ve change it to build over a ubuntu:latest image (like my test case) and all is working well.

Regards,

Ludovic
Reply all
Reply to author
Forward
0 new messages