简体   繁体   中英

Custom VSTS Build Task to Call PhantomJS Fails to Create Image File

I am in the process of writing a custom VSTS extension that (based on parameters) requests a URL and emails the results. I have all pieces of it functioning properly, except the piece that calls PhantomJS exe. This is required in order to generate the screenshot, prior to attaching to the email.

The relevant PowerShell code is as follows:

Write-Verbose "Run phantomjs with $testingurl"
Start-Process -FilePath "phantomjs.exe" -ArgumentList "screenshot.js",$testingurl
$directory = Get-ScriptDirectory
Get-ChildItem $directory -force

I am calling PhantomJS with the relevant parameters, which should create an image in my working directory called 'example.png'. However, when I then output the contents of the directory, the file is not present.

I have played around with the "scope" of my extension, but it has not helped. My current scopes are:

"scopes": [
    "vso.build_execute",
    "vso.serviceendpoint_manage",
    "vso.code_manage",
    "vso.packaging_manage",
    "vso.release_execute",
    "vso.work_write"
],

I also verified that I can create a file if I use the standard PS commandlet:

New-Item "$directory\test.txt" -ItemType file

I also tried including a blank 'example.png' in my VSIX package that would hopefully be overwritten, but it does not.

So, I'm convinced it's not a write-permission issue. The VSTS logs give no indication of the call to PhantomJS exe failing.

Are you not allowed to call an exe from a PS script from within a VSTS extension (build task)? The PS script works correctly locally so I feel this is more of an environment/permission/allowance issue than a code issue on my part.

My issue ended up being that the exe was run and my code continued to execute. I had to add the "-Wait" attribute to my call:

Start-Process -FilePath "phantomjs.exe" -ArgumentList "screenshot.js",$testingurl -Wait

Since the lines following the call to phantomjs.exe requires the execution to finish, the "-Wait" ensures it runs to completion first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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