pipeline { agent any options { timeout(time: 2, unit: 'DAYS') } stages { stage('git pull') { steps { echo 'git pull' git credentialsId: 'pw_lh', url: 'http://172.16.2.83/testtools/PaxTestByPytest.git', branch: 'dev' } } stage('Build') { steps { timeout(time: 48, unit: 'HOURS') { build job: 'CI_Version_Test_Demo', parameters: [ string(name: 'serialNo', value: '172.16.120.187:6714'), string(name: 'fastbootSerialNo', value: '1240249707'), string(name: 'product_name', value: 'A80'), string(name: 'isVersionTest', value: 'true'), string(name: 'runtime', value: '430'), string(name: 'app_runtime', value: '360'), string(name: 'monkeyapp_runtime', value: '180'), string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui') ], wait: false // build job: 'CI_Version_Test_Child', parameters: [ // string(name: 'serialNo', value: '1240249703'), // string(name: 'fastbootSerialNo', value: '1240249703'), // string(name: 'product_name', value: 'A80S'), // string(name: 'isVersionTest', value: 'true'), // string(name: 'runtime', value: '4320'), // string(name: 'app_runtime', value: '360'), // string(name: 'monkeyapp_runtime', value: '1080'), // string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui') // ], wait: false } } } } } 以上脚本添加git下载到指定文件夹:/var/lib/jenkins/workspace/CI_Code_Pull下,怎么写
时间: 2024-01-12 08:03:52 浏览: 64
jenkins-pipeline-gitflow-maven:带有Jenkinsfile的示例Maven项目正在执行基于git-flow的发布管理
要将Git代码下载到指定文件夹 `/var/lib/jenkins/workspace/CI_Code_Pull`,你可以使用Pipeline的`dir`指令来指定目标文件夹。修改你的Pipeline脚本如下:
```groovy
pipeline {
agent any
options {
timeout(time: 2, unit: 'DAYS')
}
stages {
stage('git pull') {
steps {
echo 'git pull'
dir('/var/lib/jenkins/workspace/CI_Code_Pull') {
git credentialsId: 'pw_lh', url: 'http://172.16.2.83/testtools/PaxTestByPytest.git', branch: 'dev'
}
}
}
stage('Build') {
steps {
timeout(time: 48, unit: 'HOURS') {
build job: 'CI_Version_Test_Demo', parameters: [
string(name: 'serialNo', value: '172.16.120.187:6714'),
string(name: 'fastbootSerialNo', value: '1240249707'),
string(name: 'product_name', value: 'A80'),
string(name: 'isVersionTest', value: 'true'),
string(name: 'runtime', value: '430'),
string(name: 'app_runtime', value: '360'),
string(name: 'monkeyapp_runtime', value: '180'),
string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui')
], wait: false
}
}
}
}
}
```
在脚本中,我在 `git pull` 阶段的步骤中添加了 `dir('/var/lib/jenkins/workspace/CI_Code_Pull')` 来指定下载代码的目标文件夹。然后,使用 `git` 命令在该目录下克隆指定的Git仓库。
注意确保目标文件夹 `/var/lib/jenkins/workspace/CI_Code_Pull` 存在,并且具有适当的权限,以便Jenkins能够在该目录下进行操作。
阅读全文