Jira
Since Camel 3.0
Both producer and consumer are supported
The JIRA component interacts with the JIRA API by encapsulating Atlassian’s REST Java Client for JIRA. It currently provides polling for new issues and new comments. It is also able to create new issues, add comments, change issues, add/remove watchers, add attachment and transition the state of an issue.
Rather than webhooks, this endpoint relies on simple polling. Reasons include:
-
Concern for reliability/stability
-
The types of payloads we’re polling aren’t typically large (plus, paging is available in the API)
-
The need to support apps running somewhere not publicly accessible where a webhook would fail
Note that the JIRA API is fairly expansive. Therefore, this component could be easily expanded to provide additional interactions.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jira</artifactId>
<version>${camel-version}</version>
</dependency> | Atlassian does not release their JIRA Java client to Maven Central. Therefore, when using Keep this in mind as Maven will then use this repository to download the JIRA client (and potentially other JARs). Which allows Atlassian to track these downloads by their servers. |
URI format
jira://type[?options]
The Jira type accepts the following operations:
For consumers:
-
newIssues: retrieve only new issues after the route is started
-
newComments: retrieve only new comments after the route is started
-
watchUpdates: retrieve only updated fields/issues based on provided jql
For producers:
-
addIssue: add an issue
-
addComment: add a comment on a given issue
-
attach: add an attachment on a given issue
-
deleteIssue: delete a given issue
-
updateIssue: update fields of a given issue
-
transitionIssue: transition a status of a given issue
-
watchers: add/remove watchers of a given issue
As Jira is fully customizable, you must ensure the field IDs exist for the project and workflow, as they can change between different Jira servers.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Jira component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The time between two polls of the consumer, in milliseconds unless the timeUnit option sets another unit. The producer does not use it. | 6000 | Integer | |
Required The URL of the Jira server, for example https://jira.example.com, to which the component sends its REST API requests. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
The shared configuration of the endpoints, as an org.apache.camel.component.jira.JiraConfiguration. Each endpoint starts from a copy of it, and the options of the endpoint override the copy. | JiraConfiguration | ||
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The access token. If none of the consumerKey, privateKey and verificationCode options is set, the component sends it as a personal access token in a Bearer Authorization header. Otherwise it is the OAuth 1.0a access token. Not used when the username option is set. | String | ||
The consumer key of the OAuth 1.0a application link in Jira, for OAuth authentication with the privateKey, verificationCode and accessToken options. Not used when the username option is set. | String | ||
The password for basic authentication, or an API token on Jira Cloud. Only used when the username option is set. | String | ||
The RSA private key of the OAuth 1.0a consumer, as Base64-encoded PKCS#8 without the PEM header and footer. The component signs each request with it (RSA-SHA1), for OAuth authentication. Not used when the username option is set. | String | ||
The username for basic authentication, which is the email address of the account on Jira Cloud. If set, the component uses basic authentication with the password option, and does not use the accessToken and OAuth options. | String | ||
The OAuth 1.0a verification code (oauth_verifier) that Jira showed when the user authorized the request token, for OAuth authentication with the consumerKey, privateKey and accessToken options. Not used when the username option is set. | String |
Endpoint Options
The Jira endpoint is configured using URI syntax:
jira:type
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The operation of the endpoint, case-insensitive. The consumer types are newIssues, newComments and watchUpdates. The producer types are addIssue, addComment, addIssueLink, addWorkLog, attach, deleteIssue, fetchComments, fetchIssue, transitionIssue, updateIssue and watchers. Enum values:
| JiraType |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The time between two polls of the consumer, in milliseconds unless the timeUnit option sets another unit. The producer does not use it. | 6000 | Integer | |
Required The URL of the Jira server, for example https://jira.example.com, to which the component sends its REST API requests. | String | ||
The JQL query that selects the issues that the consumer reads, for example project=CAMEL AND status=Open. The newIssues consumer adds a condition on the creation date and ORDER BY created DESC to it, so the query must not have an ORDER BY clause. Wrap the query in RAW() so that Camel does not decode it, for example RAW(project in (MYP, COM) AND resolution = Unresolved). | String | ||
The maximum number of issues that the consumer reads from the JQL search in one poll, or no limit if 0 or less: newComments reads the comments of these issues, and watchUpdates watches them. The newIssues consumer reads every issue created since its previous poll and uses this value as the page size of the search, at most 50. | 50 | Integer | |
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
Whether the watchUpdates consumer sends only the new value of the changed field as the body, for example a Status, or null when the field was cleared. If false, the body is the whole updated Issue. Either way, the consumer sends one message per watched field that changed. | true | boolean | |
The comma-separated list of the issue fields that the watchUpdates consumer watches for changes, without spaces. Each name is the name of a getter of com.atlassian.jira.rest.client.api.domain.Issue without the get prefix, case-sensitive, for example Status, Priority, Summary or Assignee. | Status,Priority | String | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean | |
The access token. If none of the consumerKey, privateKey and verificationCode options is set, the component sends it as a personal access token in a Bearer Authorization header. Otherwise it is the OAuth 1.0a access token. Not used when the username option is set. | String | ||
The consumer key of the OAuth 1.0a application link in Jira, for OAuth authentication with the privateKey, verificationCode and accessToken options. Not used when the username option is set. | String | ||
The password for basic authentication, or an API token on Jira Cloud. Only used when the username option is set. | String | ||
The RSA private key of the OAuth 1.0a consumer, as Base64-encoded PKCS#8 without the PEM header and footer. The component signs each request with it (RSA-SHA1), for OAuth authentication. Not used when the username option is set. | String | ||
The username for basic authentication, which is the email address of the account on Jira Cloud. If set, the component uses basic authentication with the password option, and does not use the accessToken and OAuth options. | String | ||
The OAuth 1.0a verification code (oauth_verifier) that Jira showed when the user authorized the request token, for OAuth authentication with the consumerKey, privateKey and accessToken options. Not used when the username option is set. | String |
Message Headers
The Jira component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelJiraIssueAssigneeId (producer) Constant: | The ID of the user to assign the issue to, which is the account ID on Jira Cloud, for addIssue and updateIssue. Not used when the CamelJiraIssueAssignee header is set. | String | |
CamelJiraIssueAssignee (producer) Constant: | The username of the user to assign the issue to, for addIssue and updateIssue. Jira Cloud identifies users by account ID instead, so use the CamelJiraIssueAssigneeId header there. | String | |
CamelJiraIssueComponents (producer) Constant: | The comma-separated list of the names of the project components to set on the issue, for addIssue and updateIssue. For updateIssue, the list replaces the components of the issue. | String | |
CamelJiraIssueChanged (consumer) Constant: | The name of the watched field that changed, as written in the watchedFields option, for example Status. The watchUpdates consumer sets it. | String | |
| Constant: | The key of the issue, for example CAMEL-1234. Required by every producer type except addIssue and addIssueLink. The watchUpdates consumer sets it to the key of the changed issue. | String | |
CamelJiraIssuePriorityId (producer) Constant: | The ID of the priority of the issue, for addIssue and updateIssue. If not set, the producer looks up the ID of the priority that the CamelJiraIssuePriorityName header names. | Long | |
CamelJiraIssuePriorityName (producer) Constant: | The name of the priority of the issue, for example High, for addIssue and updateIssue. Only used when the CamelJiraIssuePriorityId header is not set, and the name must match exactly. | String | |
CamelJiraIssueProjectKey (producer) Constant: | The key of the project to create the issue in, for example CAMEL. Required for addIssue. | String | |
CamelJiraIssueSummary (producer) Constant: | The summary of the issue. Required for addIssue. For updateIssue, it replaces the summary of the issue. | String | |
CamelJiraIssueTransitionId (producer) Constant: | The ID of the workflow transition to perform on the issue, for transitionIssue, which requires it. Jira lists the transitions of an issue at /rest/api/2/issue/{issueIdOrKey}/transitions. | Integer | |
CamelJiraIssueTypeId (producer) Constant: | The ID of the issue type, for addIssue and updateIssue. If not set, the producer looks up the ID of the issue type that the CamelJiraIssueTypeName header names. addIssue requires one of the two headers. | Long | |
CamelJiraIssueTypeName (producer) Constant: | The name of the issue type, for example Bug, for addIssue and updateIssue. Only used when the CamelJiraIssueTypeId header is not set, and the name must match exactly. | String | |
CamelJiraIssueWatchedIssues (consumer) Constant: | The comma-separated list of the keys of the issues that the watchUpdates consumer watches. The consumer builds the list when it starts, and again when the number of issues that the JQL query returns changes. | String | |
CamelJiraIssueWatchersAdd (producer) Constant: | The comma-separated list of the usernames, or of the account IDs on Jira Cloud, of the users to add as watchers of the issue, for addIssue and watchers. | String | |
CamelJiraIssueWatchersRemove (producer) Constant: | The comma-separated list of the usernames of the users to remove as watchers of the issue, for watchers. | String | |
CamelJiraParentIssueKey (producer) Constant: | The key of the first issue of the link, which the producer sends as the inward issue. Required for addIssueLink. | String | |
CamelJiraChildIssueKey (producer) Constant: | The key of the second issue of the link, which the producer sends as the outward issue. Required for addIssueLink. | String | |
| Constant: | The name of the issue link type, for example Blocks or Duplicate. Required for addIssueLink. | String | |
CamelJiraMinutesSpent (producer) Constant: | The time spent on the issue in minutes, for the work log that addWorkLog adds, which requires it. | -1 | int |
Message Body
The message body at each side of the Jira component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| One message per new Issue (newIssues) or new Comment (newComments). watchUpdates sends one per watched field that changed, with its new value, such as the Status or the BasicPriority (null when cleared), or the Issue with sendOnlyUpdatedField=false.
Not known when |
Producer input |
| Read as text: the description for addIssue and updateIssue, the comment for addComment and addWorkLog, which fail without a body, and an optional comment for transitionIssue and addIssueLink; a Map or a POJO is sent as its toString(), so marshal it first. attach uploads a file, or text, bytes or a stream named by the CamelFileName header. The other types read only headers.
|
Producer output |
| The Issue created for addIssue, the Issue for fetchIssue and the List of its Comments for fetchComments. The other types leave the body unchanged.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Client Factory
You can bind the JiraRestClientFactory with name JiraRestClientFactory in the registry to have it automatically set in the Jira endpoint.
Authentication
Camel-jira supports the following forms of authentication:
We recommend using OAuth or Personal token whenever possible, as it provides the best security for your users and system.
OAuth authentication requirements:
Follow the tutorial in Jira OAuth documentation to generate the client private key, consumer key, verification code and access token.
-
a private key, generated locally on your system.
-
A verification code, generated by Jira server.
-
The consumer key, set in the Jira server settings.
-
An access token, generated by Jira server.
Personal access token authentication requirements:
Follow the tutorial to generate the Personal Token.
-
You have to set only the personal token in the
access-tokenparameter.
JQL
The JQL URI option is used by both consumer endpoints. Theoretically, items like the "project key", etc. could be URI options themselves. However, by requiring the use of JQL, the consumers become much more flexible and powerful.
At the bare minimum, the consumers will require the following:
jira://[type]?[required options]&jql=project=[project key]
One important thing to note is that the newIssues consumer will automatically set the JQL as:
-
append
ORDER BY created DESCto your JQL -
prepend
created > latestIssueCreationDateto retrieve issues added after the camel route was started.
This is in order to optimize startup processing, rather than having to index every single issue in the project.
Each poll reads every page of that search, so the issues created since the previous poll are consumed also when there are more than maxResults of them (for example after Jira was unreachable for a while); maxResults is then the page size of the search (at most 50). There is no upper bound: after a long outage or a large import, one poll reads all the new issues, one search request per page, keeps them in memory and routes them as one batch. On Jira Cloud the pages are read with the next page token of the search, as Jira Cloud cannot page by start index. The search of Jira Cloud is eventually consistent, so a new issue can become searchable only after a newer one: when a poll has already consumed the newer one, the late issue is not consumed.
Another note is that, similarly, the newComments consumer will have to index every single issue and comment on the project. Therefore, for large projects, it’s vital to optimize the JQL expression as much as possible. For example, the JIRA Toolkit Plugin includes a "Number of comments" custom field use '"Number of comments" > 0' in your query. Also try to minimize based on state (status=Open), increase the polling delay, etc. Example:
jira://[type]?[required options]&jql=RAW(project=[project key] AND status in (Open, \"Coding In Progress\") AND \"Number of comments\">0)"
Examples
The Jira server and the credentials are component options, for example in application.properties:
camel.component.jira.jira-url = https://jira.example.com
camel.component.jira.username = {{env:JIRA_USERNAME}}
camel.component.jira.password = {{env:JIRA_PASSWORD}} The following route polls the new open issues of a project every minute. The body is the Issue:
- route:
from:
uri: jira:newIssues
parameters:
jql: "RAW(project=CAMEL AND status=Open)"
delay: 60000
steps:
- log:
message: "New issue ${body.key}: ${body.summary}" The following route creates an issue. The message body is the description, and the body after the call is the created Issue:
- route:
from:
uri: direct:report
steps:
- setHeader:
name: CamelJiraIssueProjectKey
expression:
constant:
expression: CAMEL
- setHeader:
name: CamelJiraIssueTypeName
expression:
constant:
expression: Bug
- setHeader:
name: CamelJiraIssueSummary
expression:
simple:
expression: "Order ${header.orderId} failed"
- to:
uri: jira:addIssue
- log:
message: "Created ${body.key}" Operations
See a list of required headers to set when using the Jira operations. The author field for the producers is automatically set to the authenticated user on the Jira side.
If any required field is not set, then an IllegalArgumentException is throw.
There are operations that requires id for fields such as the issue type, priority, transition. Check the valid id on your jira project as they may differ on a jira installation and project workflow.
AddIssue
Required:
-
CamelJiraIssueProjectKey: The project key, example: CAMEL, HHH, MYP. -
CamelJiraIssueTypeIdorCamelJiraIssueTypeName: Theidof the issue type or the name of the issue type, you can see the valid list inhttp://jira_server/rest/api/2/issue/createmeta?projectKeys=SAMPLE_KEY. -
CamelJiraIssueSummary: The summary of the issue.
Optional:
-
CamelJiraIssueAssignee: the assignee user -
CamelJiraIssueAssigneeId: the assignee user id -
CamelJiraIssuePriorityIdorCamelJiraIssuePriorityName: The priority of the issue, you can see the valid list inhttp://jira_server/rest/api/2/priority. -
CamelJiraIssueComponents: A list of string with the valid component names. -
CamelJiraIssueWatchersAdd: A list of strings with the usernames (or id) to add to the watcher list. -
The exchange body is used as the issue description.
AddComment
Required:
-
CamelJiraIssueKey: The issue key identifier. -
the body of the exchange is the text of the comment.
Attach
Only one file should attach per invocation.
Required:
-
CamelJiraIssueKey: The issue key identifier. -
the body of the exchange is the file to attach: a
File, the file of the file consumer, or text, bytes or a stream, named by theCamelFileNameheader
TransitionIssue
Required:
-
CamelJiraIssueKey: The issue key identifier. -
CamelJiraIssueTransitionId: The issue transitionid.
Optional:
-
the body of the exchange is a comment to add to the issue after the transition.
UpdateIssue
-
CamelJiraIssueKey: The issue key identifier. -
CamelJiraIssueTypeIdorCamelJiraIssueTypeName: Theidof the issue type or the name of the issue type, you can see the valid list inhttp://jira_server/rest/api/2/issue/createmeta?projectKeys=SAMPLE_KEY. -
CamelJiraIssueSummary: The summary of the issue. -
CamelJiraIssueAssignee: the assignee user -
CamelJiraIssueAssigneeId: the assignee user id -
CamelJiraIssuePriorityIdorCamelJiraIssuePriorityName: The priority of the issue, you can see the valid list inhttp://jira_server/rest/api/2/priority. -
CamelJiraIssueComponents: A list of string with the valid component names. -
The exchange body is used as the issue description.
Watcher
-
CamelJiraIssueKey: The issue key identifier. -
CamelJiraIssueWatchersAdd: A list of strings with the usernames (or id) to add to the watcher list. -
CamelJiraIssueWatchersRemove: A list of strings with the usernames to remove from the watcher list.
WatchUpdates (consumer)
-
watchedFieldsComma separated list of fields to watch for changes i.e.Status,Priority,Assignee,Componentsetc. -
sendOnlyUpdatedFieldBy default, only the changed field is sent as the body.
All messages also contain the following headers that add additional info about the change:
-
issueKey: Key of the updated issue -
changed: name of the updated field (i.e., Status) -
watchedIssues: list of all issue keys that are watched in the time of update