如何自动更新Docker容器中的jenkins插件?

时间:2019-04-17 15:02:29

标签: docker jenkins jenkins-plugins jenkins-cli

我有用于更新Jenkins插件的shell脚本。我想在docker容器中运行脚本(在其中运行Jenkins),以便在启动jenkins cointainer时始终运行脚本。当我在容器内手动运行脚本时,效果很好,但是当硬币容器内的詹金斯(Jenkins)起来时,如何实现脚本自动运行。

Dockerfile

FROM jenkinsci/blueocean
user root
COPY jenkins_update.sh /opt/

jenkins_update.sh

curl http://127.0.0.1:8080/jnlpJars/jenkins-cli.jar --output /opt/jenkins-cli.jar

#waiting when jenkins will be up for download
#while true; do
#   sleep 10
#   curl --fail http://localhost:8080/jnlpJars/jenkins-cli.jar --output /opt/jenkins-cli.jar && break
# done


UPDATE_LIST=$(java -jar /opt/jenkins-cli.jar -s http://localhost:8080/ -auth "admin:admin" -noKeyAuth list-plugins | grep -e ')$' | awk '{ print $1 }' );
if [ ! -z "${UPDATE_LIST}" ]; then
echo Updating Jenkins Plugins: ${UPDATE_LIST};
java -jar /opt/jenkins-cli.jar -s http://localhost:8080/ -auth "admin:admin" -noKeyAuth install-plugin ${UPDATE_LIST};
java -jar /opt/jenkins-cli.jar -s http://localhost:8080/ -auth "admin:admin" -noKeyAuth safe-restart;
fi

docker-compose.yml

my_jenkins:
    build:
      context: jenkins_config/
    ports:
      - "8080:8080"
      - "50000:50000"
    container_name: jenkins

    deploy:
          replicas: 1      
          restart_policy:
            condition: on-failure

    environment:
          - "JAVA_OPTS=-Djenkins.install.runSetupWizard=false"

        command: ["/opt/jenkins_update.sh"]

0 个答案:

没有答案