How to setup Jenkins using Docker

  1. Install Jenkins using Docker
    sudo docker run --restart always -p 8081:8080 --name=jenkins -d \
    -v /var/www/html:/var/www/html \
    --env JAVA_OPTS="-Xmx4092m" --env JENKINS_OPTS="--prefix=/jenkins" jenkins/jenkins


    Get password from tail logs command.
    docker logs --tail 100 -f <container_name>


  2. Install Jenkins Recommend plugin.

  3. Install ZTI’s Recommend plugin.
    Manage Jenkins > Plugin Manager > Available Tab
    1. Gitlab
    2. Deploy to container
    3. Maven Integration
    4. Publish over SSH
    5. Publish over FTP
  4. Install Node in docker
    docker exec -it -u root <container_name> bash
    apt-update
    apt install curl -y
    apt install wget -y
    curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
    bash nodesource_setup.sh
    apt install nodejs

  5. Install Maven in docker
    docker exec -it -u root <container_name> bash
    apt install unzip -y
    cd /opt
    wget http://www-eu.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.zip
    unzip apache-maven-3.5.4-bin.zip
    mv apache-maven-3.5.4 maven
    chown -R root:root /opt/maven

    echo 'export PATH=$PATH:/opt/maven/bin' | tee -a /etc/profile
    source /etc/profile
    mvn --version

  6. Install Maven
    Global Tool Configuration > Maven > Maven Installations > Add Maven
    Name : MVN
    MAVEN_HOME : /opt/maven
  7. Add Jenkins Credentials Provider: Jenkins
    Manage Jenkins > Credentials > System > Global Credentials (Unrestrict)


  8. Add SSH path (If needed).
    Go to Manage Jenkins > Configure System