I have this script called install-plugins.sh
that installs plugins into jenkins.
#!/bin/bash
JENKINS_URL=http://localhost:8080
PLUGINS_FILE=$1
while IFS=':' read -r plugin_name plugin_version; do
java -jar jenkins-cli.jar -s $JENKINS_URL -auth admin:admin install-plugin "${plugin_name}:${plugin_version}"
done < "$PLUGINS_FILE"
java -jar jenkins-cli.jar -s $JENKINS_URL -auth admin:admin safe-restart
I also have a txt file that has the plugin names and their versions
run-condition:1.5
blueocean-dashboard:1.27.1
blueocean-core-js:1.27.1
Whenever I run the script, the first plugin is only installed but not the others below. How do I fix this?
./install-plugins.sh plugins.txt
Installing run-condition:1.5 from update center
CodePudding user response:
Your java
will consume the rest of the STDIN. So,
run-condition:1.5
is read by the while read
, and
blueocean-dashboard:1.27.1
blueocean-core-js:1.27.1
is read by java
.
A simple solution would be to give java
its own STDIN to chew on:
while IFS=':' read -r plugin_name plugin_version; do
echo 'hoppa' | java -jar jenkins-cli.jar -s $JENKINS_URL -auth admin:admin install-plugin "${plugin_name}:${plugin_version}"
done < "$PLUGINS_FILE"