Skip to content

Instantly share code, notes, and snippets.

node('NODE') {
try {
String jsonRegisterData = "{ .. }"
stage("register data") {
sh (script: "curl -X PUT -H 'Content-Type: application/json' http://myconsul.com:8500/v1/catalog/register -d \'$jsonRegisterData\'", returnStdout: true)
}
stage("store some data") {
package org.foo
def register(String path, String data){
return sh (script: "curl -X PUT -H 'Content-Type: application/json' ${path}/catalog/register -d \'$data\'", returnStdout: true)
}
def store(String path, String key_path, String data){
return sh (script: "curl -X PUT -H 'Content-Type: application/json' ${path}/${key_path} -d \'${data}\'", returnStdout: true)
}
@Library('Jenkins-Shared-Library-Objects@with-shared-library')
def consul = new org.foo.Consul()
node('NODE') {
try {
String jsonRegisterData = "{ .. }" // A string whatever data we want in json format
String path = "http://myconsul.com:8500/v1"
package org.foo
/** A map that holds all constants and data members that can be override when constructing */
consulEnv
/**
* Imitates a constructor
* Defines an instance of Consul object. All according to api
* @param ip - ip for consul
@Library('Jenkins-Shared-Library-Objects@stateful-shared-library')
def consul = new org.foo.Consul()
node('NODE') {
try {
String jsonRegisterData = "{ .. }" // A string of whatever data we want in json format
consul.construct("http://myconsul.com", "8500")
package org.foo
/** A map that holds all constants and data members that can be override when constructing */
consulEnv
/** An HttpRest object that handles http requests */
httpHandler
def construct(httpObj){
package org.boo
httpEnv
def construct(String base_url){
httpEnv = [
base_url: base_url,
curl_options: '-sS',
debug: false,
def call(httpObj){
def consul = new org.foo.Consul()
consul.construct(httpObj)
return consul
}
def call(String base_url){
def http = new org.boo.HttpRest()
http.construct(base_url)
return http
}
@Library('Jenkins-Shared-Library-Objects@stateful-advanced')
def httpHandler = getHttpRestHandler("http://myconsul.com:8500") // constructing a HttpRest
def consul = getConsulHandler(httpHandler)
node('NODE') {
try {
String jsonRegisterData = "{ .. }" // A string of whatever data we want in json format
stage("register data") {