Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-46085

Add pipeline step to print/get the container logs

    XMLWordPrintable

Details

    Description

      The `containerTemplate` is used to run the Jenkins slave and e.g. a `mvn` container to build your code

      It can also be used to e.g. run e.g. a MongoDB in the background that is used by your tests - I guess that is a valid usecase.

      When doing this, it might be useful for debugging purposes to access the logs of the container at some point in the build, before the container terminates - as the user that writes the build might not have access to kubernetes, and also the container will terminate when {{node { }} is finished.

      We suggest adding a pipeline step that takes a container name as argument and either prints the container logs to the build log or returns them:

      def log = containerLog name: "mongo", returnLog: true
      
      containerLog name: "mongo", returnLog: false
      
      // print to log by default
      containerLog "mongo"
      

      We would be willing to implement this ourselves, if you are willing to accept this into the main codebase.

      It might also be worthwhile to add a flag to the `containerTemplate` definition allowing to stream the container logs into the build log when they occur (), in order to be able to easier correlate events from the build with events from the container log..

      Attachments

        Issue Links

          Activity

            yes, I can see this useful in a

             try {
                   // do 
               } catch (error) {
                  containerLogs('mongo')
               }
            

            although today you could do

            container('mongo') {cat /var/log/... } 
            

            if logs are also in a file

            csanchez Carlos Sanchez added a comment - yes, I can see this useful in a try { // do } catch (error) { containerLogs( 'mongo' ) } although today you could do container( 'mongo' ) {cat / var /log/... } if logs are also in a file
            0x89 Martin Sander added a comment -

            if logs are also in a file

            Which is probably not the case if you use images from dockerhub...

            0x89 Martin Sander added a comment - if logs are also in a file Which is probably not the case if you use images from dockerhub...
            csanchez Carlos Sanchez added a comment - implemented in https://github.com/jenkinsci/kubernetes-plugin/pull/195

            People

              0x89 Martin Sander
              0x89 Martin Sander
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: