Skip to content

Instantly share code, notes, and snippets.

@SrDios SrDios/publish.groovy Secret
Created Nov 14, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.