2

I have configured jenkins parameter deployment job using active choices parameterize plugin. In my dev server section have two servers called, 192.168.94.139, 192.168.94.140

array

I want to read this array input and deploy to both servers. As an example if I select both servers artifacts should be deployed to both servers. How can I read those inputs to fulfill my requirement. Until this point I wrote an array to read inputs but it prints like this

192.168.94.139,192.168.94.140

my_array=($SERVER_SELECTION)
for i in ${my_array[@]} 
do 

   echo $my_array

done

2 Answers 2

2

Look this:

#!/bin/bash
#Get servers list
set -f
string=$DEPLOY_SERVER
array=(${string//,/ })
for i in "${!array[@]}"do    
      echo "Deploy project on server ${array[i]}"    
done

I found this link

0

An elegant way is to use IFS environment variable (Internal Field Separator) to define a delimiter when assigning a string list to array.

IFS="," SERVERS=($SERVERS) #BTW, no need to declare a new variable, just reassign

for SERVER in ${SERVERS[@]} 
do 
   echo $SERVER
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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