Created
January 31, 2023 12:30
-
-
Save yitsushi/1cdb01e39adfd16a1b7454a99584b456 to your computer and use it in GitHub Desktop.
Jenkins on kind cluster with webhook plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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="[email protected]_e2ee1a_85a"> | |
<description></description> | |
<keepDependencies>false</keepDependencies> | |
<properties> | |
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> | |
<triggers> | |
<org.jenkinsci.plugins.gwt.GenericTrigger plugin="[email protected]"> | |
<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="[email protected]_d8b_e512dcf"> | |
<script>node { | |
stage "Run something" | |
echo "Awesome" | |
}</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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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