Ubuntu – Installing jenkins plugins automatically

bashdockerJenkinspluginsscripts

Im writing the script which downloads jenkins war, skip setup, then install plugins for it.
i downloaded batch-install-jenkins-plugins.sh using some link, and also created the plugins.txt file as mentioned.
when i run the script using docker it is giving me error that you must specify plugins.txt.
Here is my script:

FROM ubuntu:14.04
# Install Java.
RUN \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  apt-get update && \
  apt-get upgrade -y && \
  apt-get install -y  software-properties-common && \
  add-apt-repository ppa:webupd8team/java -y && \
  apt-get update && \
  apt-get install -y oracle-java8-installer && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk8-installer

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

# get maven 3.2.2 and verify its checksum
RUN wget --no-verbose -O /tmp/apache-maven-3.2.2.tar.gz http://archive.apache.org/dist/maven/maven-3/3.2.2/binaries/apache-maven-3.2.2-bin.tar.gz; \
echo "87e5cc81bc4ab9b83986b3e77e6b3095 /tmp/apache-maven-3.2.2.tar.gz" | md5sum -c   
ARG BASE_URL=https://apache.osuosl.org/maven/ven-3/${MAVEN_VERSION}/binaries

# install maven
RUN tar xzf /tmp/apache-maven-3.2.2.tar.gz -C /opt/; \
  ln -s /opt/apache-maven-3.2.2 /opt/maven; \
  ln -s /opt/maven/bin/mvn /usr/local/bin; \
  rm -f /tmp/apache-maven-3.2.2.tar.gz
ENV MAVEN_HOME /opt/maven


# Install dependencies
RUN apt-get -y update  && \
    apt-get -yqq --no-install-recommends install bash git bzip2 curl unzip && \
    apt-get update

# copy jenkins war file to the container
#ADD http://mirrors.jenkins.io/war-stable/2.107.1/jenkins.war /opt/jenkins.war
COPY jenkins.war /opt/jenkins.war
ENV JENKINS_HOME /jenkins

# configure the container to run jenkins, mapping container port 8080 to that host port
RUN mkdir /jenkins/
COPY proxy.xml /jenkins/proxy.xml
COPY config_updated.xml opt/config_updated.xml

COPY settings.xml /usr/share/maven/conf/settings.xml
ENTRYPOINT ["java","-jar","/opt/jenkins.war"]
ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false"

#Install plugins
RUN cd /usr/local/bin && curl -L https://raw.githubusercontent.com/hgomez/devops-incubator/master/forge-tricks/batch-install-jenkins-plugins.sh -o batch-install-jenkins-plugins.sh
RUN chmod +x /usr/local/bin/batch-install-jenkins-plugins.sh 
COPY /plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN xargs /usr/local/bin/batch-install-jenkins-plugins.sh < /usr/share/jenkins/ref/plugins.txt
RUN echo 2.0 > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state

when i build the image of above script it is giving this error:

Step 21/23 : RUN xargs /usr/local/bin/batch-install-jenkins-plugins.sh < /usr/share/jenkins/ref/plugins.txt
—> Running in 72d198deef6b
You must provide plugin file
usage: batch-install-jenkins-plugins.sh options

Install or update Jenkins Plugins.

OPTIONS:
-p –plugins file containing plugins list
-x –xplugins file containing excluded plugins list
-d –plugindir directory where to deploy plugins (.jpi)

Examples:

Run:batch-install-jenkins-plugins.sh –plugins okplugins –excludedplugins nokplugins –plugindir /var/lib/myjenkins/plugins
The command '/bin/sh -c xargs /usr/local/bin/batch-install-jenkins-plugins.sh < /usr/share/jenkins/ref/plugins.txt' returned a non-zero code: 123

FOR checking if i comment that line and changed ENTRYPOINT to bash and checked, and found plugins.txt is present in that location only
BASH OUTPUT

I need to take arguments from plugins.txt and install those plugins to jenkins, when i launch it in browser.

i refered to the link

Thank you in advance, sorry if there wrong english.

Best Answer

I am not exactly sure what is wrong with your build, but your Jenkins Dockerfile looks unnecessarily complicated. Here is a simple Dockerfile that does what you want:

FROM jenkins/jenkins:lts
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt

That installs the plugins defined in plugins.txt.

This should be enough to install your plugins automatically. However if you want to configure a complete Jenkins instance from a configuration file, check out this Jenkins plugin that allows Jenkins to be completely configured from YAML.