- Trigger Jenkins builds upon receipt of a matching message.
- Await a message in the middle of a Job.
- Send a message from Jenkins Job.
JMS Messaging Providers
- This plugin supports the following JMS Messaging Provider types
- ActiveMQ
- Kafka
- RabbitMQ
The version 2 releases the plugin are not backward-compatible with version 1 releases. Some of the incompatible changes include:
- Removal of FedMsg as a supported provider.
- Removal of CI message types.
- Authentication changed to use Jenkins credentials.
Note
This file contains only documentation for version 2 and later releases. For version 1 and earlier release documentation, please see the v1 README file.
Before the plugin may be used, you must add at least one JMS Messaging Provider. This will provide the ability to send and receive messages. Below is a list of currently supported JMS Messaging Providers:
- ActiveMQ
- Kafka
- RabbitMQ
Add the providers of your choice and provide the necessary configuration parameters. To ensure your configuration is correct, click the "Test Connection" button to validate that your connection works.
Example:
unclassified:
jmsProviders:
configs:
- activeMq:
name: "Active MQ"
broker: "foo.com:4242"
topic: "active.mq.com"
topicProvider: "default"
useQueues: false
authenticationMethod:
simple:
credentialId: "amq-username-password"
- kafka:
name: "Kafka"
topic: "default.topic"
producerProperties: "bootstrap.servers=localhost:9092"
consumerProperties: "bootstrap.servers=localhost:9092"
- rabbitMq:
name: "Rabbit MQ"
exchange: "ex"
hostname: "rabbitmq.example.com"
portNumber: "4545"
queue: "foo.bar"
topic: "baz"
virtualHost: "rabbitvh.example.com"
authenticationMethod:
sslCertificate:
keyStoreCredentialId: "rabbitmq-keystore-credential-id"
trustStoreCredentialId: "rabbitmq-truststore-credential-id"
To enable the CI trigger, go to the job configuration page and add click the check box "CI Event" under the Build Triggers section.
Note the "Schedule a new job for every triggering message checkbox". By default, Jenkins will "squash" jobs, so that if a job is queued and another triggering message is received, a new job is not submitted and the job is "squashed" into the job already queued. Checking this box will cause a job to be scheduled for every triggering message.
To access the content of the triggering message, see the Retrieving Message Content section.
The plugin provides a build step for publishing messages. To add the CI Notifier build step, go to the job configuration page, in the "Build Steps" section click the "Add Build Step" button, and then select the "CI Notifier" option.
You will then be presented with option for configuring the build step. These options differ by messaging provider. Select the messaging provider you want from the drop-down menu and then fill in the configuration options as appropriate.
Following is an example of the CI Notifier build step for an AMQ messaging provider:
The plugin provides a build step for a job to wait for messages. To add the CI Subscriber build step, go to the job configuration page, in the "Build Steps" section click the "Add Build Step" button, and then select the "CI Notifier" option.
You will then be presented with option for configuring the build step. These options differ by messaging provider. Select the messaging provider you want from the drop-down menu and then fill in the configuration options as appropriate.
Following is an example of the CI Subscriber build step for a Kafka messaging provider:
To access the content of the triggering message, see the Retrieving Message Content section.
See the CI Notifier build step documentation.
The CI Trigger is available via the triggers section in a declarative pipeline.
The easiest way to create a CI Trigger in your pipeline is to use the Declarative Directive Generator. This will allow you to configure your CI trigger and then generate the equivalent code that you can then cut and paste directly into your declarative pipeline.
To generate CI Trigger code using the Declarative Directive Generator, navigate to the generaton in the Jenkins UI, select "triggers: Trigger" from the "Sample Directive" drop-down, the click the "Add" drop-down and select "ciBuildTrigger: CI Event". Then configure your trigger and click the "Generate Declarative Directive" button.
Here's an example of what a CI trigger may look like:
triggers {
ciBuildTrigger(providers: [activeMQSubscriber(name: 'AMQ', selector: 'foo = bar')])
}
The plugin provides steps for both sending and receiving messages when using the Jenkins Pipeline feature. The easiest way to use these steps in your pipeline is to use the Snippet Generator. This will allow you to configure your pipeline step and then generate the equivalent code that you can then cut and paste directly into your pipeline.
This is the Freestyle CI Notifier Build Step and Post-Build Action sibling.
To generate code using the Snippet Generator, navigate to it in the Jenkins UI and select the sample step "sendCIMessage: CI Notifier". Then fill in the desired options to configure the step and click the "Generate Pipeline Script" button at the bottom.
A sample step may look something like this:
sendCIMessage rabbitMQPublisher(failOnError: true, messageContent: '{"msg": "This is my message"}', name: 'RabbitMQ')
For the Kafka provider, you can optionally send message headers (key=value, one per line). Header values support environment variable substitution. Example:
sendCIMessage kafkaPublisher(
name: 'Kafka',
messageContent: '{"msg": "Hello"}',
messageHeaders: 'X-My-Header=myvalue\nX-Other=${ENV_VAR}',
failOnError: true
)
withCIMessage supports ActiveMQ, RabbitMQ, and Kafka request/response exchanges.
It establishes the response subscription before starting the Pipeline body:
| Provider | Readiness barrier | Resources after completion |
|---|---|---|
| ActiveMQ | JMS queue consumer or non-durable topic consumer created | Consumer and connection closed; configured destinations preserved |
| RabbitMQ | Response queue declared, binding established, and consumer confirmed by the broker | Generated exclusive queues removed; configured queues and bindings preserved |
| Kafka | Partitions assigned and initial offsets resolved | Consumer closed; topics preserved |
For Kafka, polling continues during the body so the consumer remains in its
group even when the body exceeds max.poll.interval.ms. Automatic offset commits
are disabled for this block; the matched response offset is committed only after
the body succeeds. A matching response fetched during assignment or body execution
is retained. Consumers sharing a Kafka group split partitions; use separate group IDs
for independent response subscriptions.
The body can send a request and do other work while responses are buffered. After the body completes, the step collects a matching response and returns its JSON content:
node {
def response = withCIMessage(providerData: [
$class: 'RabbitMQSubscriberProviderData',
name: 'RabbitMQ',
overrides: [
$class: 'MessagingProviderOverrides',
topic: 'request-123.response',
queue: ''
],
checks: [],
variable: 'RPC_RESPONSE',
useFiles: false,
timeout: 5
]) {
sendCIMessage(providerData: [
$class: 'RabbitMQPublisherProviderData',
name: 'RabbitMQ',
overrides: [
$class: 'MessagingProviderOverrides',
topic: 'request-123'
],
messageContent: '{"parameter":[],"responseRoutingKey":"request-123.response"}',
failOnError: true
])
echo 'Other work can run here while the response is buffered.'
}
// Requires Pipeline Utility Steps for readJSON.
def result = readJSON(text: response, returnPojo: true)
echo "Response: ${result}"
}
For ActiveMQ or Kafka, select ActiveMQSubscriberProviderData or
KafkaSubscriberProviderData and the corresponding configured provider. The body
and returned JSON follow the same contract; provider-specific options such as
selectors, header checks, topic overrides, and file output remain available.
For the RabbitMQ example, the provider must reference the desired exchange and have a blank queue to generate an exclusive, auto-delete response queue. With a configured queue, the existing queue is used and is never deleted by this step. The service receiving the request must publish its response using the agreed routing key; the request-side queue and its binding must already exist. Use a unique response routing key per exchange or add correlation checks with a suitable queue layout.
withCIMessage does not correlate a response with the request it was sent for.
Any message that reaches the response destination between the subscription becoming ready and the
body sending its request (for example, a stray message on a shared Kafka topic) can be returned
as the response unless it is filtered out. When the destination can carry unrelated messages, use
checks or, for Kafka, headerChecks with a unique correlation ID so only the intended response matches.
The timeout above, in minutes, starts after the body completes. A response
arriving during the body is retained and can satisfy the wait immediately. Wrap
the step in Pipeline timeout to bound setup, body execution, and response wait
together. Body failures are propagated without being replaced by a message
timeout. Cancellation stops the body and receiver. RabbitMQ-generated response
queues are cleaned up on success and failure, including partial subscription setup.
Configured queues, topics, and their existing bindings are preserved.
The existing waitForCIMessage step retains its wait-only behavior. A block cannot
resume after a controller restart: it fails explicitly rather than silently
replaying a request or continuing with lost subscription state. Retry the entire
exchange with a new correlation ID only when the receiving service supports
that retry safely. Responses are acknowledged before the step returns; this is
not a transaction spanning RabbitMQ and later Pipeline stages.
This is the Freestyle CI Subscriber Build Step sibling.
To generate code using the Snippet Generator, navigate to it in the Jenkins UI and select the sample step "waitForCIMessage: CI Notifier". Then fill in the desired options to configure the step and click the "Generate Pipeline Script" button at the bottom.
A sample step may look something like this:
waitForCIMessage kafkaSubscriber(name: 'Kafka', timeout: 30, useFiles: true)
For the Kafka provider, you can optionally add header checks so that only messages whose record headers match the given name/value (regex) pairs are accepted. Example:
waitForCIMessage kafkaSubscriber(
name: 'Kafka',
timeout: 30,
headerChecks: [
headerCheck(headerName: 'X-Filter', expectedValue: 'accept')
]
)
Note
The waitForCIMessage step also returns the message content as a string.
This is in addition to the other ways the message content is available
that are described in Retrieving Message Content.
The plugin trigger and steps can be used with job DSL as well. Here's an example job DSL that creates a job with a CI Trigger, a plugin step, and a post-build action.
job('example-1') {
triggers {
ciBuildTrigger {
providers {
activeMQSubscriberProviderData {
name("AMQ")
overrides {
topic("different.topic")
}
checks {
msgCheck {
field('$.artifact.type')
expectedValue("cvp")
}
}
}
}
noSquash(true)
}
}
steps {
ciMessageSubscriberBuilder {
providerData {
activeMQSubscriber {
checks {
msgCheck {
field('$.msg')
expectedValue("sample")
}
}
name("AMQ")
selector("foo = 'bar'")
timeout(30)
}
}
}
}
publishers {
ciMessageNotifier {
providerData {
activeMQPublisher {
failOnError(true)
messageContent("{'msg': 'This is a sample message'}")
messageProperties("foo=bar")
name("AMQ")
}
}
}
}
}
Note
The Job DSL plugin is a good resource for creaing DSL for the JMS messaging plugin's trigger and job steps. Make sure the plugin is installed, then go to ${YOUR_JENKINS_URL}/plugin/job-dsl/api-viewer/index.html#plugin/jms-messaging.
By default, the trigger and the CI Subscribe job steps save the triggering message content in an environment variable that is made available in the job. The name of this variable is configurable and defaults to "CI_MESSAGE".
Note
For the AMQ provider, the trigger will also set an environment variable named "${VARIABLE}_HEADERS" with the JSON content representing the message headers.
For the Kafka provider, the trigger will also set an environment variable named "${VARIABLE}_RECORD" with the JSON content representing the entire Kafka record.
There may be instances where the message size may be too large to be stored in an environment variable. If this occurs, the job is failed.
In this case the message content can be passed in files, as detailed in the Files section.
When messages are too large to be stored in an environment variable, the plugin provides functionality for passing the message content by file. The method for configuring this differs for the trigger and the job steps.
The file name used for the message content is the value specified for the Variable in the configuration of the trigger or the step.
Note
For the AMQ provider, the trigger will also set create a file named "${VARIABLE}_HEADERS" with the JSON content representing the message headers.
For the Kafka provider, the trigger will also create a file named "${VARIABLE}_RECORD" with the JSON content representing the entire Kafka record.
To enable passing message content by file in the CI Trigger, simply create a file parameter on the job with the same name as the Variable value specified in the configuration.
Note
For the AMQ provider, if you want the headers also passed in a file, create a file parameter named "${VARIABLE}_HEADERS" on the job.
For the Kafka provider, if you want the headers also passed in a file, create a file parameter named "${VARIABLE}_RECORD" on the job.
Here's an example:
To enable passing message content by file in the CI Subscriber, check the "Use files instead of environment variables" checkbox in the configuration.
Note
For the AMQ provider, this will also result in the creation of a file named "${VARIABLE}_HEADERS" in the workspace.
For the Kafka provider, this will also result in the creation of a file named "${VARIABLE}_RECORD" in the workspace.
Here's an example:





