Hi,
I have a declarative pipeline in which I have a file called inventory which
I want to parse in Active Choice Plugin. Below is the inventory file.
[qaservers]
qa1
qa2
qa3
qa4
[devservers]
dev1
dev2
dev3
[prodservers]
prod1
prod2
I want to parse this in groovy and dynamically retrieve the values from
this file based on the branch name. How do I achieve the below result?
def get_environment_qa() {
return ["qa1", "qa2"]
}
def get_environment_dev() {
return ["dev1", "dev2"]
}
def get_environment_prod() {
return ["prod1", "prod2"]
}
if (BRANCH.startsWith("release")) {
get_environment_qa()
} else if (BRANCH.startsWith("develop")) {
get_environment_dev()
} else if (BRANCH.startsWith("master")) {
get_environment_prod()
}else {
return ["Unknown state"]
}
I have tried defining a script for get_environment_dev() as below but it
doesn't seem to be working.
def get_environment_dev() {
def inventory = readFile 'inventory'
sh 'awk \'/^\\[devservers/ {x=1; next} /^\\[/ {x=0} x==1 && !/^[\\t ]*$/\'
inventory > dev_servers'
def dev_servers = readFile'dev_servers'
return dev_servers
}
I guessed it was a problem because it is a string return and not an array.
But then I tried looping through the string and storing it array which is
also not working. Any help is appreciated. Thanks in advance
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/295866cd-435a-48ec-b268-90482077cc90%40googlegroups.com.