HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to read array and loop server selection and deployment

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
selectionreadarrayserverloophowanddeployment

Problem

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



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

Solution

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

Code Snippets

#!/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

Context

StackExchange DevOps Q#5620, answer score: 2

Revisions (0)

No revisions yet.