如何通过PowerShell从AppVeyor API获取构建作业jobid属性?

时间:2017-03-24 08:50:51

标签: powershell

我从AppVeyor API获得了这个JSON:

 $build = Invoke-WebRequest -Uri https://ci.appveyor.com/api/projects/XXX/XXX/branch/master | ConvertFrom-Json

我需要看一下这个数组:

$build.build.jobs

返回:

jobId                    : jgc1moa0o1tjdkyq
name                     : Environment: PYTHON=C:\Python35, PYTHON_VERSION=3.5.x, PYTHON_ARCH=32
allowFailure             : False
messagesCount            : 0
compilationMessagesCount : 0
compilationErrorsCount   : 0
compilationWarningsCount : 0
testsCount               : 0
passedTestsCount         : 0
failedTestsCount         : 0
artifactsCount           : 1
status                   : success
started                  : 2017-03-23T08:34:59.2087897+00:00
finished                 : 2017-03-23T08:37:03.7539463+00:00
created                  : 2017-03-23T08:34:52.1106626+00:00
updated                  : 2017-03-23T08:37:03.7539463+00:00

jobId                    : 3yqddtiapirm49ow
name                     : Environment: PYTHON=C:\Python35-x64, PYTHON_VERSION=3.5.x, PYTHON_ARCH=64
allowFailure             : False
messagesCount            : 0
compilationMessagesCount : 0
compilationErrorsCount   : 0
compilationWarningsCount : 0
testsCount               : 0
passedTestsCount         : 0
failedTestsCount         : 0
artifactsCount           : 1
status                   : success
started                  : 2017-03-23T08:37:08.5375578+00:00
finished                 : 2017-03-23T08:39:10.7684334+00:00
created                  : 2017-03-23T08:34:52.4856621+00:00
updated                  : 2017-03-23T08:39:10.7840711+00:00

我需要jobId,其中名称包含Python35-X64

以下表达式什么都不返回,我做错了什么?

$job_id = $build.build.jobs | where { $_.name -like "*Python35-X64*" }

1 个答案:

答案 0 :(得分:1)

您的表达式不返回任何内容,因为结果已分配给变量$(document).ready(function () { link = 'http://example.com/image.jpg'; chrome.downloads.download({ url: link, filename: './' + link.substr(link.lastIndexOf('/')+1), saveAs: false }); }); 。在这种情况下,变量不包含作业的id,而是包含作业对象。

$job_id

注意:如果您没有选择第一个结果,$job = $build.build.jobs |? name -like "*Python35-X64*" | Select-Object -First 1; $job; $job_id = $job.jobId; 将包含多个名称与where子句匹配的作业数组。

如果您想直接选择$job属性,可以按照以下步骤进行操作。

jobId