`
sillycat
  • 浏览: 2564479 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Jenkins 2019 in Docker(4)Cluster using Docker

 
阅读更多
Jenkins 2019 in Docker(4)Cluster using Docker

Check the docker version on 2 machines
> docker --version
Docker version 18.09.2, build 6247962
Master and Slave, set the public key to ssh each other, major is just the Master need to SSH to Slave
Manage Jenkins —> Manage Nodes —> We can see there is one master nodes with 60.27GB disk space
New Node —> Node Name: slave1 —> Permanent Agent
In the next page, I put some informations as follow:
Name: slave1
#of executors: 2
Remote root directory: /opt/jenkins/jensins_home_slave
Labels: slave1
Usage: Use this node as much as possible
Launch method: Launch agent agents via SSH
Host: IP address of the slave machine
Credentials: I use root and use private key to ssh to the slave
Host Key Verification Strategy: Non verifying Verification Strategy
Availability: Keep this agent online as much as possible.
Here is my Jenkins file in pipeline script:
pipeline {
  options {
    buildDiscarder(logRotator(numToKeepStr: '50'))
  }
  agent {
    dockerfile {
      filename 'deployment/jenkins/Dockerfile.build'
      args '-u root:root -v $HOME/.m2:/root/.m2 -v /var/run/docker.sock:/var/run/docker.sock'
    }
  }
  stages {
    stage('Clone Code') {
      steps {
        git(url: 'https://github.com/sillycatInc/NetsuiteConnector', branch: 'master', changelog: true, poll: true, credentialsId: 'github')
      }
    }
    stage('Compile and Unit Test') {
      steps {
        sh 'mvn clean'
        sh 'mvn compile'
        sh 'mvn -Dtest=WsClientServiceTest test'
      }
    }
    stage('Release to Artifactory') {
      steps {
        sh 'mvn package -DskipTests=true'
        withCredentials([string(credentialsId: 'artifactory', variable: 'TOKEN')]) {
        sh '''
      set +x
      jfrog rt config --url https://artifactory.sillycat.com/artifactory --user kikokang --apikey $TOKEN --interactive=false
      jfrog rt u target/netsuiteconnector-*-bundle.tar.gz sillycat-java/com/sillycat/netsuiteconnector/1.0/
      rm -fr target
    '''
        }
      }
    }
  }
}
I think it is not good to use root and I do not think directly run on slave is a good idea. I will check other solution later.

References:
https://www.cnblogs.com/stulzq/p/9297260.html
https://www.jianshu.com/p/ab5c0bbe02de
https://chanjarster.github.io/post/jenkins-cluster/
https://my.oschina.net/mrpei123/blog/1975952
https://stackoverflow.com/questions/48223200/jenkins-pipeline-using-docker-on-existing-slaves
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics