Answers: <p>Look this: </p>
  
  <pre><code>#!/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
  </code></pre>
  
  <p>I found this <a href="https://medium.com/@lucabecchetti/autodeploy-from-gitlab-to-multiple-aws-ec2-instances-a43448727c5a" rel="nofollow noreferrer">link</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2018-12-12T15:47:03.650Z
Answers: 2018-12-12T15:47:03.650Z
Answers: dalmo.santos
Answers: <p>An elegant way is to use <strong>IFS environment variable</strong> (Internal Field Separator) to define a <em>delimiter</em> when assigning a string list to array.</p>
  <pre class="lang-bash prettyprint-override"><code>IFS=&quot;,&quot; SERVERS=($SERVERS) #BTW, no need to declare a new variable, just reassign
  
  for SERVER in ${SERVERS[@]} 
  do 
     echo $SERVER
  done
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-02-09T11:35:56.463Z
Answers: 2021-02-09T11:42:28.840Z
Answers: 2021-02-09T11:42:28.840Z
Answers: bebyx
Body: <p>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</p>
  
  <p><a href="https://i.sstatic.net/Ble8u.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Ble8u.png" alt="array"></a> </p>
  
  <p>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 </p>
  
  <blockquote>
    <p>192.168.94.139,192.168.94.140</p>
  </blockquote>
  
  <pre><code>my_array=($SERVER_SELECTION)
  for i in ${my_array[@]} 
  do 
  
     echo $my_array
  
  done
  </code></pre>
  
Tags: <jenkins><jenkins-plugins><shell-script>
Title: How to read array and loop server selection and deployment
UserDisplayName: Janith
ThreadText: # How to read array and loop server selection and deployment
  
  (Asked by: username_0 on 2018-12-05)
  
  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](https://i.sstatic.net/Ble8u.png)](https://i.sstatic.net/Ble8u.png)
  
  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
  
  ```
  
  **Tags:** jenkins, jenkins-plugins, shell-script
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-12-12. Score: 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](https://medium.com/@lucabecchetti/autodeploy-from-gitlab-to-multiple-aws-ec2-instances-a43448727c5a)
  
  
  ---
  
  ### Answer by username_2 on 2021-02-09. Score: 0
  
  An elegant way is to use **IFS environment variable** (Internal Field Separator) to define a *delimiter* when assigning a string list to array.
  
  ```bash
  IFS="," SERVERS=($SERVERS) #BTW, no need to declare a new variable, just reassign
  
  for SERVER in ${SERVERS[@]} 
  do 
     echo $SERVER
  done
  
  ```
  
  
  ---
  
  