简体   繁体   English

Jenkins 作业无需构建步骤即可创建 Powershell Jenkins 自动化

[英]Jenkins Job gets created without Build Steps Powershell Jenkins Automation

My team has an online Jenkins on a VM and we are all using that.我的团队在 VM 上有一个在线 Jenkins,我们都在使用它。 We want to install Jenkins locally for testing purposes and multi tasking.我们想在本地安装 Jenkins 用于测试目的和多任务处理。 I wrote a script that gets all the jobs from the online Jenkins and uploads them to my local Jenkins.我编写了一个脚本,从在线 Jenkins 获取所有作业并将它们上传到我本地的 Jenkins。 The problem is that the job gets uploaded without the build steps.问题是作业在没有构建步骤的情况下被上传。 But when I look into the config.xml, the steps are there, but they simply aren't displayed on the dashboard and they aren't run.但是当我查看 config.xml 时,这些步骤就在那里,但它们根本没有显示在仪表板上,也没有运行。

This is how I upload them:这就是我上传它们的方式:

$headers = @{'Authorization' = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$($Password)")); 'Jenkins-Crumb' = $Crumb }
        $response = Invoke-WebRequest `
            -Uri "$($Url)createItem?name=$JobName" `
            -Headers $headers `
            -ContentType "text/xml" `
            -Body $JobConfig `
            -WebSession $Global:crumbSession `
            -Method Post

What I suspect is that when I look at the config.xml of the online Jenkins, the config looks like this:我怀疑的是,当我查看在线 Jenkins 的 config.xml 时,配置如下所示:

<?xml version='1.1' encoding='UTF-8'?>
<project>
  <actions/>
  <description>

but the one that get's uploaded on my local Jenkins looks like this:但是上传到我本地 Jenkins 的那个看起来像这样:

<?xml version="1.1" encoding="UTF-8"?>
<project>
  <actions/>
  <description>

There is a slight difference between them, the single quote and the double quote for example, aswell as some HTML entities that are being converted.它们之间存在细微差别,例如单引号和双引号,以及一些正在转换的 HTML 实体。 Other than this, I have no clue why it isn't displaying the build steps, as I mentioned the builders tag is there in both configs, exactly the same but it simply won't appear on the dashboard and it won't get runned.除此之外,我不知道为什么它不显示构建步骤,因为我提到构建器标签在两个配置中都存在,完全相同,但它根本不会出现在仪表板上,也不会运行.

Thanks for the read:)感谢阅读:)

So after some digging, I managed to find the root cause of this.所以经过一番挖掘,我设法找到了这个问题的根本原因。 The problem is that the versions of the two Jenkins are different.问题是两个Jenkins的版本不同。 The online Jenkins has a version of 2.176.3 and my local Jenkins is a little higher 2.222.4.网上的Jenkins的版本是2.176.3,我本地的Jenkins是2.222.4高一点的。 Loading a job from an old version to a new one leads to some errors while loading the job.将作业从旧版本加载到新版本会导致加载作业时出现一些错误。 Apperently backwards compatibility isn't a thing for Jenkins:).显然向后兼容性不是 Jenkins 的问题:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM