0
votes

I am using Jenkin job to automatically update the consul key using https endpoint. The syntax I am using to update the consul key "a/b/c" is mentioned below:-

curl -f -s --show-error "https://example.com/a/b/c?AdminKey=xxxxx&token=yyyyyyy&value=nnn”. (Here key is -->a/b/c)

The above command works fine and updates consul key “a/b/c” to value “nnn”

Now I want to fetch the value of same key "a/b/c" in a variable then how I can fetch using curl command similar to what I have used for updating key?

Note: I have tried curl command such as v1=curl -f -s --show-error "https://example.com/a/b/c?AdminKey=xxxxx&token=yyyyyyy” where "v1" is a temp variable to hold the value. But this is not working. Thanks

1

1 Answers

0
votes

You can update a key using this syntax.

curl --request PUT --fail --silent --show-error "http://localhost:8500/v1/kv/a/b/c?token=<token>" --data 'nnn'

The value can then be retrieved and stored in a variable using this command.

export VARIABLE=$(curl --fail --silent --show-error "http://localhost:8500/v1/kv/a/b/c?token=<token>&raw")

See https://www.consul.io/api-docs/kv for more info on the supported arguments for these API calls.