I am trying to set helm "post-install" hook and seeing below error. ERROR: sh: script/jenkins.sh: not found
postinstall.yaml content
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}"
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": post-install
"helm.sh/hook-weight": "-5"
spec:
template:
spec:
containers:
- name: post-install-jenkins-job
image: alpine:3.3
imagePullPolicy: IfNotPresent
command: [ "/bin/sh", "-c", "scripts/jenkins.sh"]
restartPolicy: Never
terminationGracePeriodSeconds: 0
Folder structure of helm package scripts/jenkins.h is the script that I am trying to execute with "postinstall.yaml" as post-install helm hook.
riq-agent
├── Chart.yaml
├── README.md
├── scripts
│ └── jenkins.sh
├── templates
│ ├── NOTES.txt
│ ├── Untitled-1.yml
│ ├── _helpers.tpl
│ ├── awssecret.yaml
│ ├── clusterrolebinding.yaml
│ ├── configurationFiles-configmap.yaml
│ ├── deployment.yaml
│ ├── hook-aws-ecr.yaml
│ ├── initializationFiles-configmap.yaml
│ ├── postinstall.yaml
│ ├── pvc.yaml
│ ├── secrets.yaml
│ ├── serviceaccount.yaml
│ ├── servicemonitor.yaml
│ ├── svc.yaml
│ └── tests
│ ├── test-configmap.yaml
│ └── test.yaml
└── values.yaml
Is there any mistakes in the way that I am trying to execute a shell script (stored within helm package) in helm hook?
In order to be executed, scripts/jenkins.sh should be a part of post-install-jenkins-job container, mounted as a volume. You can populate a volume with data stored in a configmap.
postinstall-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-postinstall-configmap
data:
jenkins.sh: |-
{{ .Files.Get "scripts/jenkins.sh" | indent 4}}
postinstall.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}"
annotations:
"helm.sh/hook": post-install
"helm.sh/hook-weight": "-5"
spec:
template:
spec:
containers:
- name: post-install-jenkins-job
image: alpine:3.3
imagePullPolicy: IfNotPresent
command: [ "/bin/sh", "-c", "/opt/scripts/jenkins.sh"]
volumeMounts:
- name: config-volume
mountPath: /opt/scripts
volumes:
- name: config-volume
configMap:
name: {{ .Release.Name }}-postinstall-configmap
defaultMode: 0777
restartPolicy: Never
terminationGracePeriodSeconds: 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With