Interconnecting Jenkins with SWR

During Jenkins installation and deployment, Docker commands have been executed in the container. Therefore, no additional configuration is required for Jenkins to connect to SWR. You can run the Docker commands to complete the build, login, and push operations.

Obtaining a Long-Term Valid Login Command

For details, see Obtaining a Long-Term Valid Login Command.

For example, the command of this account is as follows:

docker login -u cn-east-3@xxxxx -p xxxxx swr.cn-east-3.myhuaweicloud.com

Creating a Pipeline to Build and Push Images

The pipeline creation procedure is as follows:

  1. Create a pipeline on Jenkins.

  2. Configure only the pipeline script.

    Pipeline script:

    • git url is the address of your code repository. Replace it with the actual address.
    • The docker login command is the command obtained in Obtaining a Long-Term Valid Login Command.
    • Replace batch in the docker build and docker push commands with an organization name in SWR. Otherwise, the images cannot be pushed to SWR.
    node('master'){ 
           stage('Clone') { 
                  echo "1.Clone Stage" 
                  git url: "https://github.com/lookforstar/jenkins-demo.git" 
                  script { 
                         build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim() 
                  } 
           } 
           stage('Test') { 
           echo "2.Test Stage" 
           } 
           stage('Build') { 
                  echo "3.Build Docker Image Stage" 
                  sh "docker build -t swr.cn-east-3.myhuaweicloud.com/batch/jenkins-demo:${build_tag} ." 
           } 
           stage('Push') { 
                  echo "4.Push Docker Image Stage" 
                  sh "docker login -u cn-east-3@USO32ZAYF95IT3FOE06U -p 5ee790e3ac51bd4e55a8345952e80de563f6d95155a04ab4f5b03ce6fe35a707 swr.cn-east-3.myhuaweicloud.com" 
                  sh "docker push swr.cn-east-3.myhuaweicloud.com/batch/jenkins-demo:${build_tag}" 
           } 
    }

  3. Save the settings and execute the Jenkins job.

Changing the Number of Executors

  1. On the Jenkins console, choose Manage Jenkins > Manage Nodes, right-click the master node, and choose Configure Slave Node.

  2. Change the value of executors to the number of concurrent builds.