Signal forwarding with docker jenkins plugin

Viewed 38

I'm working with docker jenkins plugin, to build and run an image as follows:

                stage('Build app image') {
                    app_image = docker.build('app')
                    }

                app_image.inside("--init"){
                   stage ('Run app') {
                       try {
                          sh 'cd /app/ && python3 app/main.py' 
                       } catch (err) {
                          echo "Run app failed: ${err}"
                          currentBuild.result = 'FAILURE'
                       }
                   }
                   stage('Do stuff') {
                       ### 
                       }
                }
                

I want the pipeline to run the stage 'Do stuff' even if the pipeline is stopped by the user through the Jenkins interface. I know that Jenkins sends a SIGTERM signal, but I don't know how I can forward it to the "python3 app/main.py" process, which is able to trap and handle a SIGTERM signal.

By looking at the pipeline log, I can see that the Jenkins interface translates the pipeline code to the following docker commands:

              $ docker run -t -d -u 1000:1000 --init -w /jenkins_folder -v jenkins_folder 
              :/jenkins_folder :rw,z -v /jenkins_folder @tmp:/jenkins_folder @tmp:rw,z app_image cat   
              $ docker top 80597e9aba86ad9ec793d528ada25fcf49a8e6c027b3186b65aa9ff16c9e5651 -eo 
              pid,comm
              [Pipeline] {
              [Pipeline] stage
              [Pipeline] { (Run app)
              [Pipeline] sh
              cd /app/
              python3 app/main.py
0 Answers
Related