{jenkins-plugin-info:consul}

Consul plugin for reading services using consul service discovery and K/V store.

The plugin installs an agent, joins to the consul network, reads the necessary data and then leaves the network.

Features

Settings

Consul installation

Global configurations

Global settings configured using profiles for each environment / consul network.

Profile name - Name of the profile, will be used in the job configuration.

Masters list - Comma separated list of consul masters.

Datacenter - Consul datacenter to join (default is 'dc1' if not configured in consul installation).

Token - ACL token to join gossip network (leave empty if not needed).

 

Job configurations

Consul installation - Choose consul version (list of installations configured in jenkins global configurations).

Settings profile - Choose which consul settings profile you would like to use.

Consul operations

  Retrieve value from K/V store

    K/V path - Consul path for value retrieval.

    Environment variable name - Env var to populate the value with.

  Service discovery query

    Service lookup name - Name of the service to lookup in consul.

    Add Port? - Adding the port after each ip in the response.

    Health status - Healthy / Unhealthy / All - filtering for service lookup.

    Service tag - Tagging filtering for service lookup.

    Environment variable name - Env var to populate the CSV list of extracted ip addresses.

  Set a value in K/V store

    K/V path - Path in consul to set the value.

    value - Environment variable name that holds the value or any other static value to set in consul.

 

Consul build step can be added multiple times within the same job. Each step can use different consul settings profile.

This gives the ability to query multiple consul clusters & query them in a single run.

 

Pipeline

Since version 2.0 the plugin supports pipeline.

Consul pipeline step will return JSON value with the required data.

Use the pipeline syntax tool (https://your-jenkins-master-url/pipeline-syntax/) to generate the code.

 

node {
	def consulJson = Consul consulSettingsProfileName: 'inneractive', installationName: 'consul_0.7.1', operationList: [[$class: 'ConsulServiceDiscoveryOperation', addPort: true, healthStatus: 'Healthy', serviceName: 'aerospike', serviceTag: ''], [$class: 'ConsulGetKV', valuePath: 'db/main/ip'], [$class: 'ConsulSetKV', value: 'value', valuePath: 'test/consul/value']]
	echo consulJson
}
{"ServiceDiscovery":{"aerospike":["XXX.XXX.XXX.XXX:3000","XXX.XXX.XXX.XXX:3000","XXX.XXX.XXX.XXX:3000"]},"KeyValueStore":{"db/main/ip":"XXX.XXX.XXX.XXX"}}

 

ToDo

Changelog

Version 2.1 (July 26, 2017)

Version 2.0 (June 5, 2017)

Version 1.0 (April 4, 2017)