修改jenkins的job配置文件config.xml来更新remote git 信息

本文详细介绍如何在Jenkins中批量更新Git仓库的密码,包括定位job目录、编辑config.xml文件以及修改credentialsId对应的密码ID值,适用于Git密码更改后的Jenkinsjob配置更新。
Goal: Create Job that will integrate with new SCR Repo Structure, enabling integration with Jenkins Enable the requirement for a Nightly Trigger of the Image Build, pulling the latest status of the develop branch. If successful, provide artifacts for use in other jobs. High-Level Summary This job will allow for Jenkins to perform a full image compile, pulling the latest changes from the mono-repo's develop branch. The job's artifacts will be used for other job's as it will continuously reflect the latest state of the branch. Enable Nightly Trigger Locate "Triggers" Section -> Check Build Periodically Then set a schedule To trigger at 2:XX AM, on Week-Days Only H 2 * * 1-5 Other Examples include: Every night at 3:30 AM 30 3 * * * Weekdays at 2:00 AM 0 2 * * 1-5 Weekends at 4:00 AM 0 4 * * 6,0 Every 6 hours starting at midnight 0 0,6,12,18 * * * Project Parameters Locate the This project is parameterized checkbox: "BUILD_DIR_IN_DOCKER" Parameter Identify which directory In the Docker Image you need to be in to build Build Steps 1. Repo Initialization and Environment Setup Locate "Build Steps" and Click on Add build step -> Execute Shell Ensure repo_tool_offline.tar.gz is in the correct path (i.e. "$HOME", etc. ) # REPO INITIALIZATION AND ENVIRONMENT SETUP # - Sets up repo tool environment and downloads source code # - Configures git settings for Jenkins CI user # - Initializes repository with product-specific branch and manifest # - Performs incremental repo sync to get latest changes env # Informational; Mostly for debugging # Only clean and initialize if .repo doesn't exist or is incomplete if [ ! -d ".repo/repo" ] || [ ! -d ".repo/manifests" ]; then echo "Repo not initialized or incomplete, setting up..." rm -rf .repo prplos prplink #Remove Any dirs related to source code mkdir -p .repo/repo tar -xzf /home/tplink/repo_tool_offline.tar.gz -C .repo NEED_INIT=true else echo "Repo already initialized, skipping setup..." NEED_INIT=false fi # Set git name and email (always safe to set) git config --global user.name "Jenkins CI" git config --global user.email "jenkins@tp-link.com" # Disable git UI color git config --global color.ui false # Set environment variables to prevent any network calls export REPO_NO_SELF_UPDATE=1 export GIT_TERMINAL_PROMPT=0 export GIT_SSH_COMMAND="ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" # Only run repo init if we just cleaned/extracted if [ "$NEED_INIT" = true ]; then echo "Running repo init (first time)..." # REPLACE THE BELOW INFORMATION WITH APPROPRIATE REPOSITORY AND BRANCH repo init -u ssh://gerrit/prplink_projects -b Deco/be65pro_v1 -m manifest.xml echo "Running repo init (second time)..." # REPLACE THE BELOW INFORMATION WITH APPROPRIATE REPOSITORY AND BRANCH repo init -u ssh://gerrit/prplink_projects -b Deco/be65pro_v1 -m manifest.xml fi # Run repo sync - first attempt (will be killed) echo "Starting repo sync (first attempt - will kill after 3 seconds)..." repo sync -c -j14 -vv & SYNC_PID=$! sleep 3 kill $SYNC_PID 2>/dev/null || true wait $SYNC_PID 2>/dev/null || true echo "Killed first sync attempt, waiting a moment..." sleep 1 # Always run the final sync (either fresh or incremental) echo "Running repo sync..." repo sync -c -j14 -vv echo "Repo sync completed successfully!" # REPLACE THE BELOW DIR APPROPRIATE DIR cd prplos repo forall -c ' # Only run if HEAD is detached if [ -z "$(git symbolic-ref --short -q HEAD)" ]; then # Get the remote branch names from origin/gerrit for b in $(git branch -r | grep "gerrit/" | sed "s|gerrit/||"); do # Just pick the branch that exists remotely git checkout -B $b gerrit/$b break done fi ' cd ../
最新发布
12-20
**第十八部分:Jenkins Nightly Image Build Job 配置指南** --- ### **1. 目标与背景** - 创建一个 Jenkins Job,与新的 SCR 仓库结构集成。 - 配置 Nightly 定时触发,拉取 `develop` 分支的最新代码。 - 成功构建后生成构建产物(Artifacts),供其他 Job 使用。 --- ### **2. 创建 Jenkins Job** #### **2.1 登录 Jenkins Web UI** - 进入 **Home > New Item**。 - 输入 Job 名称,例如: ``` be65 Pro Nightly Image Build ``` - 选择 **Freestyle project**。 - 点击 **OK**。 --- ### **3. 配置定时触发器(Nightly Trigger)** #### **3.1 启用定时构建** - 在 **Build Triggers** 区域,勾选 **Build periodically**。 #### **3.2 设置定时表达式** ```cron H 2 * * 1-5 ``` - 表示:**工作日 02:00 AM** 触发构建(周一至周五)。 > 📌 **其他示例:** > - 每天凌晨 3:30:`30 3 * * *` > - 周末 04:00:`0 4 * * 6,0` > - 每 6 小时一次:`0 0,6,12,18 * * *` --- ### **4. 配置 Job 参数** #### **4.1 启用参数化构建** - 勾选 **This project is parameterized**。 #### **4.2 添加参数** | 参数名称 | 类型 | 示例值 | 用途说明 | |----------|------|--------|-----------| | `BUILD_DIR_IN_DOCKER` | String | `/prplos/platform/src/public/dropbear` | 指定 Docker 构建路径 | --- ### **5. 构建步骤配置(Build Steps)** #### **5.1 Repo 初始化与环境准备(Execute Shell)** ```bash # REPO INITIALIZATION AND ENVIRONMENT SETUP env # Only clean and initialize if .repo doesn't exist or is incomplete if [ ! -d ".repo/repo" ] || [ ! -d ".repo/manifests" ]; then echo "Repo not initialized or incomplete, setting up..." rm -rf .repo prplos prplink #Remove Any dirs related to source code mkdir -p .repo/repo tar -xzf /home/tplink/repo_tool_offline.tar.gz -C .repo NEED_INIT=true else echo "Repo already initialized, skipping setup..." NEED_INIT=false fi # Set git name and email (always safe to set) git config --global user.name "Jenkins CI" git config --global user.email "jenkins@tp-link.com" git config --global color.ui false # Set environment variables to prevent any network calls export REPO_NO_SELF_UPDATE=1 export GIT_TERMINAL_PROMPT=0 export GIT_SSH_COMMAND="ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" # Only run repo init if we just cleaned/extracted if [ "$NEED_INIT" = true ]; then echo "Running repo init (first time)..." repo init -u ssh://gerrit/prplink_projects -b Deco/be65pro_v1 -m manifest.xml echo "Running repo init (second time)..." repo init -u ssh://gerrit/prplink_projects -b Deco/be65pro_v1 -m manifest.xml fi # Run repo sync - first attempt (will be killed) echo "Starting repo sync (first attempt - will kill after 3 seconds)..." repo sync -c -j14 -vv & SYNC_PID=$! sleep 3 kill $SYNC_PID 2>/dev/null || true wait $SYNC_PID 2>/dev/null || true echo "Killed first sync attempt, waiting a moment..." sleep 1 # Always run the final sync (either fresh or incremental) echo "Running repo sync..." repo sync -c -j14 -vv echo "Repo sync completed successfully!" cd prplos repo forall -c ' if [ -z "$(git symbolic-ref --short -q HEAD)" ]; then for b in $(git branch -r | grep "gerrit/" | sed "s|gerrit/||"); do git checkout -B $b gerrit/$b break done fi ' cd ../ ``` --- ### **6. 构建镜像(Build Image)** #### **6.1 使用 Docker 容器化构建(Execute Shell)** ```bash # CONTAINERIZED BUILD VERIFICATION CONTAINER_ID=$(docker run -d -u compile -v "$WORKSPACE/prplos:/home/compile/prpLink" ubuntu18.04-be65pro:latest tail -f /dev/null) # Run commands inside the container docker exec $CONTAINER_ID sh -c " echo 'Current user:' whoami echo 'Current directory:' pwd cd ${BUILD_DIR_IN_DOCKER} make MODEL=be65pro SPEC=TEST all " docker stop $CONTAINER_ID docker rm $CONTAINER_ID echo "--- Build process complete ---" ``` --- ### **7. 构建产物归档(Archive the Artifacts)** #### **7.1 添加 Post-Build Action** - 在 **Post-Build Actions** 区域,点击 **Add post-build action**。 - 选择 **Archive the Artifacts**。 - 设置归档路径,例如: ``` prplos/output/*.bin ``` --- ### **8. 工作区清理(Optional)** #### **8.1 添加清理脚本(Execute Shell)** ```bash #!/bin/bash set -e set -u # 清理旧的构建文件 rm -rf prplos prplink .repo echo "Workspace cleaned up successfully." ``` --- ### **9.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IDO老徐

转发 + 讨论 > 赞赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值