I provided the script to provision a new feature environment inside k8s it will create all the configs required, namespaces, resources and whatever...

in my script, I described this param:

parameters {
text(name: 'SERVICE_LIST', defaultValue: '', description: 'Services to deploy, separated by line breaks.')}

when the developer is provisioning a new env, he will provide a list of services that he wants to enable on that environment

also in my script, I described the following piece of code which are enabling all services requested(its located inside the stage and step):

def services = replaced.split('\\n')
   services.each { SERVICE ->
    sh "echo turning on service ${SERVICE}"
    sh "yq w -i  ${DEPLOY_ENV_FOLDER}/services.yaml '${SERVICE}.enabled' true"}

this is an example of a services file:

service file

so, when the developer provides the services that he wants, the script goes to this file, enable the services and apply to k8s

now my question is how to assure that the services provided by the developer are correct and that they exist in the file? otherwise, I need to abort the script. I tried to use try{} catch{} in the second piece of code above to define the exception for abort services which are provided by developers incorrectly, do you have any other solution?


@Mkash, don't you know in advance what services you have in your services.yaml file?

Maintain a list in groovy, and see whether the input is in that list or not.

Something like:

availableServices = ["ew_ws_gateway", "ingress"]

services = ["a", "b", "c", "ew_ws_gateway"]

services.each { svc ->
    if (svc in availableServices) {
        println("Service exist" + svc)

The other option is to change the parameter from type of text to multiple-choice possibly using https://plugins.jenkins.io/extended-choice-parameter/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.