Skip to content

Instantly share code, notes, and snippets.

@SrDios
Created November 14, 2018 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SrDios/8a449f0f5ad76ed1cf015027e3f292a3 to your computer and use it in GitHub Desktop.
Save SrDios/8a449f0f5ad76ed1cf015027e3f292a3 to your computer and use it in GitHub Desktop.
Publish apiary pipeline
stage('PUBLISH APIARY') {
container(name:jenkinsAgentSelector.podTemplateContainerName, shell: '/bin/bash') {
deleteDir()
sh "mkdir -p ${templateParams.endpointName}"
dir("${templateParams.endpointName}"){
componentBuilder.checkoutByBranch('master')
def endpointJSON = readFile file: templateParams.endpointFile
endpointInformation = new JsonSlurperClassic().parseText(endpointJSON)
endpointInformation = new com.fts.cp.endpoint.parser.EndpointParser(this, endpointInformation)
endpointName = endpointInformation.endpoint.name
endpointProfileType = endpointInformation.endpoint.profile.profileType
endpointPath = endpointInformation.endpoint.path
def mainSwaggerPath = "endpoints" + "/swagger" + "/swagger_main.json"
def upstreamHost = (endpointInformation.endpoint.name.toLowerCase()+'-'+templateParams.stageName).replace('_','-')
def endpointNameSanitized = (endpointInformation.endpoint.name + '-ep').toLowerCase().replace('_','-')
endpointUpstreamUrl = 'http://'+upstreamHost+'.'+endpointInformation.endpoint.infrastructure+'/'+endpointInformation.endpoint.version.slug+'/api/'+endpointNameSanitized
finalUpstreamUrl = endpointUpstreamUrl
if(templateParams.stageName == 'ci') {
try{
withCredentials([string(credentialsId: 'apiaryApiKey', variable: 'TOKEN')]){
//apiaryManager.publishSwaggerToApiaryByJson(TOKEN, templateParams.endpointFile)
publishSwaggerToApiaryByJson(TOKEN, mainSwaggerPath)
finalUpstreamUrl = apiaryManager.mockServer + endpointPath
}
}catch(error){
print("This error is because apiary is not accessible or the endpoint documentation update failed")
}
}else{
println("Not needed to publish since it is not CI")
}
}
}
}
def publishSwaggerToApiaryByJson(apiaryApiKey, swaggerMain){
steps.sh ("cat $swaggerMain > swagger.json")
steps.sh ("swagger-combine swagger.json -o swaggerInfo.json")
def apiaryInspectorUrl = 'https://'+apiName+'.docs.apiary.io/traffic'
steps.sh ("export APIARY_API_KEY=$apiaryApiKey && apiary publish --api-name=$apiName --path=\"swaggerInfo.json\" --json")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment