How to run a cd-jobs which are in your helm charts, as a separate step in the deploy stage to run a test.
Let’s say you have a usecase to run a cd-jobs which is in your helm charts, as a separate step in the deploy stage to run a test. Then how do we achieve this?
-
If cd-jobs are in the templates directory helm will try and deploy it alongside the rest of the app. You can add
# harness.io/skip-file-for-deploy
to the file to let harness know to ignore it, but that doesn’t tell other services that you use to deploy or manual helm installs, which will try to deploy this job file. -
Moving cd-jobs to the templates dir and wrapping the job definition in a values conditional will work, and you can achieve the usecase, but if you prefer it out of the templates dir, then the following steps will help you to achieve this.
I would like to offer some alternatives, which don’t need any changes to your repo structure or add the harness.io/skip-file-for-deploy. With these suggested solutions, it’ll still allow the helm chart to be deployed outside of Harness.
Solution [#1]
The first solution would be to update your custom script to conditionally move the cd-jobs directory only for the apply step. Here’s an example using a " test directory" and with the step, name Apply:
if [[ "<+step.name>" == "Apply" ]]; then echo "Moving test to mychart/templates directory" mv test mychart/templatesfi
Solution [#2]
The second solution would be to update the job’s YAML in place using the sed. I would like to reinforce that this would only happen during the deployment, which would not be reflected in your source repo. Here’s a sample script to perform the necessary updates:
echo "Moving test to mychart/templates directory"mv test mychart/templatesecho "Add harness.io/skip-file-for-deploy to job.yaml to skip job execution during helm deploy step"sed -i '1i # harness.io/skip-file-for-deploy' mychart/templates/test/job.yaml
This is how you can run cd-jobs which are in your helm charts, as a separate step in the deploy stage to run a test.