Jenkins Pipelines: LAB: Jenkins CD with Docker, Trivy, GitOps, and Kubernetes - Part 1

This is related to Jenkins Pipelines: LAB: Jenkins CD with Docker, Trivy, GitOps, and Kubernetes - Part 1.
I’m unable to get pass task 2/9 not because of the stage(‘Build Docker Image’) I’ve added to the Jenkinsfile but because of the stage NPM Dependency Audit.

I’ve experienced several issues with this exercise which I’ve listed below:

  1. I have configured the Jenkinsfile 2 different ways; one from the OS level by doing a vi Jenkinsfile and then "git add ., git commit -m “added Build Docker Image stage” and lastly git push origin feature/enabling-cicd. I have also configured the Jenkinsfile from Gitea and committed the changes from there. This has not made any change in behaviour.

  2. I’m not 100% sure if we are supposed to create the /var/lib/jenkins/workspace/lar-system_feature_enabling-cicd/coverage/lcov-report directory prior to running a build but that directory doesn’t exist out of the box. I created the directory on the command line and changed the permissions to jenkins:jenkins using the chown command.

  3. I also noticed that some of the files under /var/lib/jenkins/workspace/lar-system_feature_enabling-cicd/node_modules where owned by root, some owned by the jenkins user. I changed the ownership recursively from node_modules onwards.

  4. The task mentions • Tag: Use the Git Commit environment variable. but in the Solutions-tab, the GIT_COMMIT is not added to the Jenkinsfile under environment. Why is that? Also, if you are using an environment variable you should use double quotes (“”) as the instructor mentioned but I have also tried with single quotes; didn’t make any difference.

  5. I also installed the Pipeline NPM Integration plugin while troubleshooting the issue. Not sure if that was needed?

As far as I understand, point 2 is related to Code Coverage stage which is not yet triggered because the pipeline already fails at the NPM Dependency Audit stage.

I’ve spent 2 days working on the lab trying different things to solve the problem so I really need some help please.

Please find screenshots showing the task in question, configuration of the Build Docker Image stage in the Jenkinsfile, screenshots from the Blue Ocean of the pipeline and from the Classic view as well.






Thanks,
@ewiklund

Hi @ewiklund

Please share the lab link so I can easily check it and provide support.

https://learn.kodekloud.com/user/courses/jenkins-pipelines/module/fb6b2c83-178c-4962-b4e6-ca5528721170/lesson/ef298b92-e6d9-4b41-810b-d4c67b0c1023

Hi Raymond,

Sorry for bothering you regarding this.
I managed to fix the problem by suppressing an Exit Code with || true in the NPM Dependency Audit stage:

        sh 'npm audit --audit-level=critical || true'

I also manually added the coverage/lcov-report directory, changed the ownership of the directories to jenkins:jenkins and this resulted in Success.




Thanks for looking into this. I will go ahead and close the post.
Regards,
@ewiklund

I want to add one more thing…After running through the complete lab several times; I can confirm that I did not have to create and change ownership of the /coverage/lcov-report directories.