-
-
Save SrDios/8a449f0f5ad76ed1cf015027e3f292a3 to your computer and use it in GitHub Desktop.
Publish apiary pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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