Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created January 31, 2023 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yitsushi/1cdb01e39adfd16a1b7454a99584b456 to your computer and use it in GitHub Desktop.
Save yitsushi/1cdb01e39adfd16a1b7454a99584b456 to your computer and use it in GitHub Desktop.
Jenkins on kind cluster with webhook plugin
#!/usr/bin/env bash
helm repo add jenkins https://charts.jenkins.io
helm install for-pipelines jenkins/jenkins \
-f jenkins-values.yaml \
-n jenkins \
--create-namespace
export NODE_PORT=$(kubectl get --namespace jenkins -o jsonpath="{.spec.ports[0].nodePort}" services for-pipelines-jenkins)
export NODE_IP=$(kubectl get nodes --namespace jenkins -o jsonpath="{.items[0].status.addresses[0].address}")
export BASE_URL="http://${NODE_IP}:${NODE_PORT}"
echo -e "\nWaiting for Jenkins to be available at ${BASE_URL}";
while ! curl -sL "${BASE_URL}" >/dev/null 2>&1; do
sleep 1;
done
curl -sLO "${BASE_URL}/jnlpJars/jenkins-cli.jar"
export ADMIN_PASS=$(kubectl exec --namespace jenkins -it svc/for-pipelines-jenkins -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password)
java -jar jenkins-cli.jar \
-s "${BASE_URL}" \
-auth "admin:${ADMIN_PASS}" \
get-job test >/dev/null 2>&1
if [[ $? != 0 ]]; then
cat <<-EOF | java -jar jenkins-cli.jar -s "${BASE_URL}" -auth "admin:${ADMIN_PASS}" create-job test
<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@1268.v6eb_e2ee1a_85a">
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers>
<org.jenkinsci.plugins.gwt.GenericTrigger plugin="generic-webhook-trigger@1.86.2">
<spec></spec>
<regexpFilterText></regexpFilterText>
<regexpFilterExpression></regexpFilterExpression>
<printPostContent>false</printPostContent>
<printContributedVariables>false</printContributedVariables>
<causeString>Generic Webhook</causeString>
<token>epicsecret</token>
<tokenCredentialId></tokenCredentialId>
<silentResponse>false</silentResponse>
<overrideQuietPeriod>false</overrideQuietPeriod>
<shouldNotFlattern>false</shouldNotFlattern>
<allowSeveralTriggersPerBuild>false</allowSeveralTriggersPerBuild>
</org.jenkinsci.plugins.gwt.GenericTrigger>
</triggers>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@3606.v0b_d8b_e512dcf">
<script>node {
stage &quot;Run something&quot;
echo &quot;Awesome&quot;
}</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>
EOF
fi
echo "${BASE_URL}"
echo ""
echo "Trigger the job:"
echo "curl -s ${BASE_URL}/generic-webhook-trigger/invoke?token=epicsecret"
controller:
serviceType: NodePort
numExecutors: 1
additionalPlugins:
- generic-webhook-trigger:1.86.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment