Skip to content

Instantly share code, notes, and snippets.

@ericjsilva
Created August 28, 2013 12:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericjsilva/6365620 to your computer and use it in GitHub Desktop.
Save ericjsilva/6365620 to your computer and use it in GitHub Desktop.
Sample MuleSoft flow using the Jenkins connector against CloudBees to get information about a job, and then execute the job. NOTE: Code will not execute the job due to the fact that CloudBees requires a POST request and the Jenkins connector issues a GET request.

Overview

I created a build at CloudBees that simply checks out the hudson-demo project at GitHub. It doesn't do a build or anything, just checks out the code.

Files

This Gist has four files:

  • CBJenkins.mflow - this is the flow file automatically created by MuleStudio. I added it in case you needed it.
  • CBJenkins.xml - this is the XML configuration metadata used to define the flow in MuleStudio. Theoretically you should be able to create a new flow in MuleStudio, the paste this XML into the Configuration XML tab in the editor.
  • mule-app.properties - I externalized some of the variables that get repeated. I added the values I used. You can change them easily enough.
  • README.md - this readme file.

References

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:jenkins="http://www.mulesoft.org/schema/mule/jenkins" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/jenkins http://www.mulesoft.org/schema/mule/jenkins/1.0/mule-jenkins.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<jenkins:config name="jenkinsconf" jenkinsUrl="https://ericjsilva.ci.cloudbees.com" connectionName="main" username="ericjsilva@gmail.com" password="your.password.here" doc:name="Jenkins"/>
<flow name="API-GET-JENKINS-INFO" doc:name="API-GET-JENKINS-INFO">
<http:inbound-endpoint exchange-pattern="request-response" host="${http.server}" port="${http.port}" path="jenkins/info" doc:name="HTTP"/>
<jenkins:get-jenkins-node-info config-ref="jenkinsconf" doc:name="Jenkins"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="API-GET-JENKINS-JOB-INFO" doc:name="API-GET-JENKINS-JOB-INFO">
<http:inbound-endpoint exchange-pattern="request-response" host="${http.server}" port="${http.port}" path="jenkins/jobinfo" mimeType="application/json" doc:name="HTTP"/>
<jenkins:get-job-info config-ref="jenkinsconf" jobName="test-job-mulesoft" doc:name="Jenkins"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="API-JENKINS-BUILD-JOB" doc:name="API-JENKINS-BUILD-JOB">
<http:inbound-endpoint exchange-pattern="request-response" host="${http.server}" port="${http.port}" path="jenkins/build" mimeType="application/json" doc:name="HTTP"/>
<jenkins:build config-ref="jenkinsconf" jobName="test-job-mulesoft" doc:name="Jenkins"/>
</flow>
</mule>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mule-configuration xmlns="http://www.mulesoft.com/tooling/messageflow" name="CBJenkins">
<global-element name="Jenkins" type="http://www.mulesoft.org/schema/mule/jenkins/config" entity-id="Jenkins#1">
<properties>
<property name="username" value="ericjsilva@gmail.com"/>
<property name="jenkinsUrl" value="https://ericjsilva.ci.cloudbees.com"/>
<property name="name" value="jenkinsconf"/>
<property name="password" value="Sith@l0rd"/>
<property name="connectionName" value="main"/>
<property name="auxiliary;index" value="1"/>
</properties>
</global-element>
<flow SubFlow="false" name="API-GET-JENKINS-INFO" entity-id="6fa9c3a3-620a-4406-a3fb-4b340c3c4ac0">
<properties>
<property name="processingStrategy"/>
<property name="processingStrategy2"/>
<property name="bussinessEventsLabel"/>
<property name="auxiliary;index" value="2"/>
<property name="tracking:enable-default-events"/>
</properties>
<lane hadOnlyOneElement="false" index="0" isChoiceOtherwiseLane="false" entity-id="compartment-lane#1">
<graphicalData x="0" y="0" width="0" height="0"/>
<endpoint direction="Inbound" message-exchange-pattern="RequestResponse" name="HTTP" type="http://www.mulesoft.org/schema/mule/http/endpoint" entity-id="HTTP#1">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name="port" value="${http.port}"/>
<property name="host" value="${http.server}"/>
<property name="businessEventsLabel"/>
<property name="followRedirects"/>
<property name="org.mule.tooling.ui.modules.core.widgets.meta.ModeAttribute" value="http://www.mulesoft.org/schema/mule/http/endpoint"/>
<property name="keep-alive"/>
<property name="contentType"/>
<property name="disableTransportTransformer"/>
<property name="password"/>
<property name="exchange-pattern" value="request-response"/>
<property name="tracking:enable-default-events"/>
<property name="ref"/>
<property name="transformer-refs"/>
<property name="httpLabel"/>
<property name="address"/>
<property name="path" value="jenkins/info"/>
<property name="encoding"/>
<property name="responseTransformer-refs"/>
<property name="method"/>
<property name="user"/>
<property name="auxiliary;index" value="3"/>
<property name="responseTimeout"/>
<property name="mimeType"/>
<property name="connector-ref"/>
</properties>
</endpoint>
<pattern name="Jenkins" type="http://www.mulesoft.org/schema/mule/jenkins/jenkins-connector" entity-id="Jenkins#2">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name=""/>
<property name="username"/>
<property name="jenkinsUrl"/>
<property name="org.mule.tooling.ui.modules.core.widgets.meta.ModeAttribute" value="http://www.mulesoft.org/schema/mule/jenkins/get-jenkins-node-info"/>
<property name="password"/>
<property name="connectionName"/>
<property name="config-ref" value="jenkinsconf"/>
<property name="auxiliary;index" value="4"/>
</properties>
</pattern>
<pattern name="Object to JSON" type="http://www.mulesoft.org/schema/mule/json/object-to-json-transformer" entity-id="Object to JSON#1">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name="sourceClass"/>
<property name="returnClass"/>
<property name="ignoreBadInput"/>
<property name="encoding"/>
<property name="mapper-ref"/>
<property name="auxiliary;index" value="5"/>
<property name="mimeType"/>
</properties>
</pattern>
</lane>
<apikit>false</apikit>
</flow>
<flow SubFlow="false" name="API-GET-JENKINS-JOB-INFO" entity-id="d8b52422-85f3-4b44-b9fc-c40485d34999">
<properties>
<property name="processingStrategy"/>
<property name="processingStrategy2"/>
<property name="bussinessEventsLabel"/>
<property name="auxiliary;index" value="6"/>
<property name="tracking:enable-default-events"/>
</properties>
<lane hadOnlyOneElement="false" index="0" isChoiceOtherwiseLane="false" entity-id="compartment-lane#2">
<graphicalData x="0" y="0" width="0" height="0"/>
<endpoint direction="Inbound" message-exchange-pattern="RequestResponse" name="HTTP" type="http://www.mulesoft.org/schema/mule/http/endpoint" entity-id="HTTP#2">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name="port" value="${http.port}"/>
<property name="host" value="${http.server}"/>
<property name="businessEventsLabel"/>
<property name="followRedirects"/>
<property name="org.mule.tooling.ui.modules.core.widgets.meta.ModeAttribute" value="http://www.mulesoft.org/schema/mule/http/endpoint"/>
<property name="keep-alive"/>
<property name="contentType"/>
<property name="disableTransportTransformer"/>
<property name="password"/>
<property name="exchange-pattern" value="request-response"/>
<property name="tracking:enable-default-events"/>
<property name="ref"/>
<property name="transformer-refs"/>
<property name="httpLabel"/>
<property name="address"/>
<property name="path" value="jenkins/jobinfo"/>
<property name="encoding"/>
<property name="responseTransformer-refs"/>
<property name="method"/>
<property name="user"/>
<property name="auxiliary;index" value="7"/>
<property name="responseTimeout"/>
<property name="mimeType" value="application/json"/>
<property name="connector-ref"/>
</properties>
</endpoint>
<pattern name="Jenkins" type="http://www.mulesoft.org/schema/mule/jenkins/jenkins-connector" entity-id="Jenkins#3">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name=""/>
<property name="username"/>
<property name="jenkinsUrl"/>
<property name="org.mule.tooling.ui.modules.core.widgets.meta.ModeAttribute" value="http://www.mulesoft.org/schema/mule/jenkins/get-job-info"/>
<property name="password"/>
<property name="connectionName"/>
<property name="jobName" value="test-job-mulesoft"/>
<property name="config-ref" value="jenkinsconf"/>
<property name="auxiliary;index" value="8"/>
</properties>
</pattern>
<pattern name="Object to JSON" type="http://www.mulesoft.org/schema/mule/json/object-to-json-transformer" entity-id="Object to JSON#2">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name="sourceClass"/>
<property name="returnClass"/>
<property name="ignoreBadInput"/>
<property name="encoding"/>
<property name="mapper-ref"/>
<property name="auxiliary;index" value="9"/>
<property name="mimeType"/>
</properties>
</pattern>
</lane>
<apikit>false</apikit>
</flow>
<flow SubFlow="false" name="API-JENKINS-BUILD-JOB" entity-id="e0e661bd-48b0-4243-9362-5c4d627dd3b3">
<properties>
<property name="processingStrategy"/>
<property name="processingStrategy2"/>
<property name="bussinessEventsLabel"/>
<property name="auxiliary;index" value="10"/>
<property name="tracking:enable-default-events"/>
</properties>
<lane hadOnlyOneElement="false" index="0" isChoiceOtherwiseLane="false" entity-id="compartment-lane#3">
<graphicalData x="0" y="0" width="0" height="0"/>
<endpoint direction="Inbound" message-exchange-pattern="RequestResponse" name="HTTP" type="http://www.mulesoft.org/schema/mule/http/endpoint" entity-id="HTTP#3">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name="port" value="${http.port}"/>
<property name="host" value="${http.server}"/>
<property name="businessEventsLabel"/>
<property name="followRedirects"/>
<property name="org.mule.tooling.ui.modules.core.widgets.meta.ModeAttribute" value="http://www.mulesoft.org/schema/mule/http/endpoint"/>
<property name="keep-alive"/>
<property name="contentType"/>
<property name="disableTransportTransformer"/>
<property name="password"/>
<property name="exchange-pattern" value="request-response"/>
<property name="tracking:enable-default-events"/>
<property name="ref"/>
<property name="transformer-refs"/>
<property name="httpLabel"/>
<property name="address"/>
<property name="path" value="jenkins/build"/>
<property name="encoding"/>
<property name="responseTransformer-refs"/>
<property name="method"/>
<property name="user"/>
<property name="auxiliary;index" value="11"/>
<property name="responseTimeout"/>
<property name="mimeType" value="application/json"/>
<property name="connector-ref"/>
</properties>
</endpoint>
<pattern name="Jenkins" type="http://www.mulesoft.org/schema/mule/jenkins/jenkins-connector" entity-id="Jenkins#4">
<graphicalData x="0" y="0" width="0" height="0"/>
<properties>
<property name=""/>
<property name="username"/>
<property name="jenkinsUrl"/>
<property name="org.mule.tooling.ui.modules.core.widgets.meta.ModeAttribute" value="http://www.mulesoft.org/schema/mule/jenkins/build"/>
<property name="password"/>
<property name="connectionName"/>
<property name="jobName" value="test-job-mulesoft"/>
<property name="config-ref" value="jenkinsconf"/>
<property name="auxiliary;index" value="12"/>
</properties>
</pattern>
</lane>
<apikit>false</apikit>
</flow>
<description></description>
</mule-configuration>
#** GENERATED CONTENT ** Mule Custom Properties file.
#Fri Aug 23 15:59:30 EDT 2013
http.server=localhost
http.port=8585
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment