tencent cloud

masukan

Step 2:Slave pod build configuration

Terakhir diperbarui:2023-05-06 17:36:46
    This document describes how to build a slave pod in Jenkins by creating and configuring a job.
    Note
    The UI of Jenkins varies with the product version. Select an appropriate version based on your business needs.

    Creating a Job

    1. Log in to the Jenkins backend and click New Item or Create an item.
    2. On the page that appears, configure the basic information of the job.
    Enter an item name: Enter a custom name. This document uses test as an example.
    Select Freestyle project.
    3. Click OK to go to the job parameter configuration page.
    4. Configure the job basic information.
    Description: Enter the descriptive information of the job. This document uses slave pod test as an example.
    This is project is parameterized: Check this option and choose Add Parameter > Git Parameter.

    Configuring Job Parameters

    1. On the Git Parameter panel, configure the following parameters as shown below:
    
    The following describes the main parameters. For other parameters, simply keep them as their defaults:
    Name: Enter mbranch, which can be used to match and obtain a branch.
    Parameter Type: Select Branch or Tag.
    2. Choose Add Parameter > Extended Choice Parameter. On the panel that appears, configure the following parameters as shown below:
    
    The following describes the main parameters. For other parameters, simply keep them as their defaults:
    Name: Enter name, which can be used to obtain the image name.
    Basic Parameter Types: Check this option.
    Parameter Type: Select Check Boxes.
    Value: Check this option and enter a custom image name. The name will be passed to the name variable. This document uses nginx,php as an example.
    3. Choose Add Parameter > Extended Choice Parameter. On the panel that appears, configure the following parameters as shown below:
    
    The following describes the main parameters. For other parameters, simply keep them as their defaults:
    Name: Enter version, which can be used to obtain the image tag variable.
    Basic Parameter Types: Check this option.
    Parameter Type: Select Text Box to obtain the image value in text format and pass it to the version variable.
    4. Check Restrict where this project can be run. For Label Expression, enter the pod label jnlp-agent set in the Configuring the slave pod template step as shown below:
    

    Configuring Source Code Management

    In the Source Code Management tab, check Git and configure the following settings:
    Repositories:
    Repository URL: Enter your GitLab repository address, such as https://gitlab.com/user-name/demo.git.
    Credentials: Select the authentication credential created in the Adding the GitLab credential step.
    Branches to build:
    **Branch Specifier (blank for 'any')**: Enter $mbranch, which is used to dynamically obtain the branch. Its value corresponds to the value of mbranch defined in "Git Parameter".

    Configuring the Shell Packaging Script

    1. In the Build tab, choose Add build step > Execute Shell.
    2. Copy and paste the following script to the Command entry box. Then, click Save.
    Note
    In this script, information such as the GitLab repository address, TKE image address, and username and password of the image repository are used as examples only. In actual cases, replace them based on your needs.
    Make sure that you 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 the “Containers” 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:
    Obtain the selected branch, image name, and image tag.
    Publish the docker image combined and built with the code to the TKE image repository.

    Subsequent Operations

    You have now successfully built the slave pod. Next, go to Building Tests to publish and verify images.
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24