This step describes how to build a slave pod in Jenkins by creating a task and configuring task parameters.
test
as an example.slave pod test
as an example.mbranch
, which can be used to match and obtain a branch.name
, which can be used to obtain the image name.name
variable. This document uses nginx,php
as an example.version
, which can be used to obtain the image tag variable.version
variable.jnlp-agent
set in the Configuring the slave pod template step.In the "Source Code Management" area, select Git and configure the following information.
https://gitlab.com/user-name/demo.git
.$mbranch
, which is used to dynamically obtain the branch, and its value corresponds to the value of mbranch
defined in "Git Parameter".In the "Building" area, choose Add Building Step > Run Shell.
Copy and paste the following script content into the "Command" entry box. Then, click Save.
- In this script, information such as the GitLab address, TKE image address, and username and password of the image repository are for example only. In actual cases, replace them based on your needs.
- Be sure to build the package based on the source code of Docker build. In addition, the working directory
/home/Jenkins/agent
must be consistent with the working directory of the container template in "Container List".
echo "GitLab address: https://gitlab.com/[user]/[project-name]].git"
echo "Selected branch (image): "$mbranch", set branch (image) version: "$version"
echo "TKE image address: hkccr.ccs.tencentyun.com/[namespace]/[ImageName]"
echo "1. Log in to the TKE image repository"
docker login --username=[username] -p [password] hkccr.ccs.tencentyun.com
echo "2. Build the package based on the source code of Docker build:"
cd /home/Jenkins/agent/workspace/[project-name] && docker build -t $name:$version
echo "3. Upload the Docker image to the TKE repository:"
docker tag $name:$version hkccr.ccs.tencentyun.com/[namespace]/[ImageName]:$name-$version
docker push hkccr.ccs.tencentyun.com/[namespace]/[ImageName]:$name-$version
The script provides the following features:
You have now successfully built the slave pod. Next, go to Building Tests to publish and verify images.
Was this page helpful?