Monday, March 25, 2024

Understanding jenkinsfile, Dockerfile, and deployment YAML files

JenkinsFile is loaded and called by jenkins server for build and deployment. Ths code in this file will run in the default jnlp container.

The podTemplate method defined in Jenkins file specifies multiple container's with name and image id. Inside the podTemplate method, it can access git commit and branch info through scmInof.GIT_COMMIT and scmInof.GIT_BRANCH.

You can define multiple steps for build and deployment by calling stage method with their unique name, if a stage succeeds, it will run the next one. If a stage fails, it will abort the jenkins file execution. Within each stage method implementation, call container () method with name parameter to indicate which container should run the code, 

In one step, the stage method is called on nodejs container to build the project

In one following step, the stage method is called on docker container to build the docker image, which will use the Dockerfile, it then tags docker image, and push it to docker registration.

After the docker image is published, then a new stage method can run in kubectl container to apply the infrastructure yaml file defined for each deployment, within the deployment yaml file, it specifies the docker image id which is published in previous step, and create a new container image for its service.


Please refer to the below link for more details

https://www.jenkins.io/doc/pipeline/steps/kubernetes/


 



No comments:

Post a Comment