Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "container" keyword in Jenkins?

I recently inherited a code base with some Jenkins files. In one of them I ran into this syntax

            stage('Prepare database for integration tests') {
                steps {
                    container('postgres') {
                        sh "..."
                    }
                }
            }

Our Jenkins is running on Openshift and the pod has multiple containers including this postgres one. However I can't find any references for using the container or connecting to a container with container('containerName') like that.

I tried to create a separate pipeline with the following piece

                        container('az-cli') {
                            try {
                                sh 'ls'
                            } catch (error) {
                                throw error
                            }
                        }

And ls listed the content in the code repository - not the container. Clearly container is not doing what I thought it does and I can't find any documentation on it. Does anyone know what this is supposed to do?

Thanks in advance.

like image 350
melis Avatar asked Dec 29 '25 15:12

melis


2 Answers

Ok, It apparently comes from the Kubernetes plugin. More documentation is in this jenkins github repo and in this jenkins documentation.

And also it was working but the 'ls' command was deceiving. When I ran an actual Azure command I saw the command result also see the logs of the container.

Thank you everyone.

like image 148
melis Avatar answered Jan 03 '26 20:01

melis


If the container(...) method is not documented it is likely being loaded by a custom library.

Check for the @Library annotation in your pipeline or if it is not part of an automatically loaded lib. You'll then find the groovy file where it is declared.

More info at https://jenkins.io/doc/book/pipeline/shared-libraries/#using-libraries

like image 45
otonglet Avatar answered Jan 03 '26 20:01

otonglet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!