slave container provisioning on kubernetes

11/16/2021

i am using kubernetes plugin in jenkins.i want to run an init script before slave container provision on kubernetes.the kubernetes plugin pod template won't allow me to or i cannot find a way to run it.can anybody please help me with this.i need to run a certain set of commands on the kubernetes slave container before it provisions.this is how my config looks like enter image description here

-- Shaswat Vashistha
cicd
jenkins
kubernetes

1 Answer

11/16/2021

1 - You don't need to use the slave image, jenkins will have an agent container regardless, you should only specify containers you want it to run additionally.

2 - On the containers you can specify the entrypoints or pre-provision whatever you want beforehand and just worry about the execution. That means you can get a container ready to go and assume the code will be there, if you need to run any extra commands on the code, you can just add an extra script step

3 - In order for your step to be executed in a container, you have to be explicit in your pipeline, otherwise it will run on the master.

I can't really guide you to using the UI because I use the Jenkinsfile inside projects I want to build.

-- Magus
Source: StackOverflow