有可能在两个不同的詹金斯之间交换工作吗?我正在寻找一种输出/输入工作的方法。
当前回答
有一个叫Job Import plugin的插件可能就是你要找的。我用过。它确实存在从不允许匿名访问的服务器导入项目的问题。
完整性: 如果您有命令行访问这两个任务,您可以执行Khez已经提到的移动、复制和重命名Jenkins作业的过程。
其他回答
有一个叫Job Import plugin的插件可能就是你要找的。我用过。它确实存在从不允许匿名访问的服务器导入项目的问题。
完整性: 如果您有命令行访问这两个任务,您可以执行Khez已经提到的移动、复制和重命名Jenkins作业的过程。
这并不适用于现有的工作,但是有Jenkins工作生成器。
这允许我们将作业定义保存在yaml文件和git repo中,这是非常可移植的。
对于那些在Windows世界中可能有或没有Bash可用的人,这里是我对Katu的PowerShell移植和Larry Cai的方法。希望它能帮助到别人。
##### Config vars #####
$serverUri = 'http://localhost:8080/' # URI of your Jenkins server
$jenkinsCli = 'C:\Program Files (x86)\Jenkins\war\WEB-INF\jenkins-cli.jar' # Path to jenkins-cli.jar on your machine
$destFolder = 'C:\Jenkins Backup\' # Output folder (will be created if it doesn't exist)
$destFile = 'jenkins-jobs.zip' # Output filename (will be overwritten if it exists)
########################
$work = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
New-Item -ItemType Directory -Force -Path $work | Out-Null # Suppress output noise
echo "Created a temp working folder: $work"
$jobs = (java -jar $jenkinsCli -s $serverUri list-jobs)
echo "Found $($jobs.Length) existing jobs: [$jobs]"
foreach ($j in $jobs)
{
$outfile = Join-Path $work "$j.xml"
java -jar $jenkinsCli -s $serverUri get-job $j | Out-File $outfile
}
echo "Saved $($jobs.Length) jobs to temp XML files"
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null # Suppress output noise
echo "Found (or created) $destFolder folder"
$destPath = Join-Path $destFolder $destFile
Get-ChildItem $work -Filter *.xml |
Write-Zip -Level 9 -OutputPath $destPath -FlattenPaths |
Out-Null # Suppress output noise
echo "Copied $($jobs.Length) jobs to $destPath"
Remove-Item $work -Recurse -Force
echo "Removed temp working folder"
Jenkins将作业导出到一个目录
#! /bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
declare -i j=0
for i in $(java -jar jenkins-cli.jar -s http://server:8080/jenkins list-jobs --username **** --password ***);
do
let "j++";
echo $j;
if [ $j -gt 283 ] // If you have more jobs do it in chunks as it will terminate in the middle of the process. So Resume your job from where it ends.
then
java -jar jenkins-cli.jar -s http://lxvbmcbma:8080/jenkins get-job --username **** --password **** ${i} > ${i}.xml;
echo "done";
fi
done
进口工作
for f in *.xml;
do
echo "Processing ${f%.*} file.."; //truncate the .xml extention and load the xml file for job creation
java -jar jenkins-cli.jar -s http://server:8080/jenkins create-job ${f%.*} < $f
done
一行程序:
$ curl -s http://OLD_JENKINS/job/JOBNAME/config.xml | curl -X POST 'http://NEW_JENKINS/createItem?name=JOBNAME' --header "Content-Type: application/xml" -d @-
身份验证:
$ curl -s http:///<USER>:<API_TOKEN>@OLD_JENKINS/job/JOBNAME/config.xml | curl -X POST 'http:///<USER>:<API_TOKEN>@NEW_JENKINS/createItem?name=JOBNAME' --header "Content-Type: application/xml" -d @-
使用Crumb,如果CSRF是活动的(参见这里的详细信息):
获取面包屑:
$ CRUMB_OLD=$(curl -s 'http://<USER>:<API_TOKEN>@OLD_JENKINS/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
$ CRUMB_NEW=$(curl -s 'http://<USER>:<API_TOKEN>@NEW_JENKINS/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
使用-H crumb涂抹crumb:
$ curl -s -H $CRUMB_OLD http:///<USER>:<API_TOKEN>@OLD_JENKINS/job/JOBNAME/config.xml | curl -X POST -H $CRUMB_NEW 'http:///<USER>:<API_TOKEN>@NEW_JENKINS/createItem?name=JOBNAME' --header "Content-Type: application/xml" -d @-
推荐文章
- 如何使用GitHub Org Plugin从jenkins管道(jenkinsfile)触发另一个作业?
- 在GitHub repo上显示Jenkins构建的当前状态
- Hudson支持的JUnit XML格式规范是什么?
- Maven依赖项失败,出现501错误
- 我怎么能让詹金斯CI与Git触发器推到主人?
- 如何从命令行重置Jenkins安全设置?
- 如何在不重启服务器的情况下停止詹金斯上不可阻挡的僵尸工作?
- Jenkins:注释可以添加到Jenkins文件中吗?
- 如何在Jenkins中设置发件人地址?
- 为某些代码关闭声纳
- 如何在Jenkins中设置环境变量?
- 我如何在詹金斯克隆一份工作?
- 如何在本地测试对詹金斯文件所做的更改?
- 在Git中更改电子邮件地址
- 从docker内部运行docker是否可以?