3

I have a PowerShell task in my definition that calls another script file on its own which takes care of running several things on my build agent (starts several different processes) - emulators, node.js applications, etc.

Everything is fine up until the moment this step is done and the run continues. All of the above mentioned stuff gets closed with most of the underlying processes killed, thus, any further execution (e.g. tests run) is doomed to fail.

My assumption is that these processes are somehow dependent on the outermost (temporary) script that VSTS generates to process the step.

I tried with the -NoExit switch specified in the arguments list of my script, but to no avail. I've also read somewhere a suggestion to set this by default with a registry key for powershell.exe - still nothing.

The very same workflow was okay in Jenkins. How can I fix this?

These are the tasks I have:

VSTS tasks

The last PowerShell task calls a specified PowerShell file which calls several others on its own. They ensure some local dependencies and processes needed to start executing the tests, e.g. a running Node.js application (started in a separate console for example and running fine).

When the task is done and it is successful, the last one with the tests would fail because the Node.js application has been shut down as well as anything else that was started within the previous step. It just stops everything. That's why I'm currently running the tests within the same task itself until I find out how to overcome this behavior.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    So finally, I used a task which calls a *bat* file with the following content: **powershell -command %1** Then within the build task itself, I provide within a single argument the path to the PowerShell script file and all the arguments (set as runtime variables from another task(s)) e.g. **"& '$(MyScriptPath)' $(MyArgs)"** – Ivaylo Angelov Apr 21 '17 at 21:38

2 Answers2

2

I am not sure how you call the dependencies and applications in your PowerShell script. But I tried with the following command in PowerShell script task to run a Node.js application:

invoke-expression 'cmd /c start powershell -Command {node main.js}'

The application keeps running after the PowerShell script task is passed and finished which should meet your requirement. Refer to this question for details: PowerShell launch script in new instance.

But you need to remember to close the process after the test is finished.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • 1
    This, together with a '-noexit' switch seems like a solution for the usual case. I tried this by calling another script which calls then several others and it was running fine. However I had some hard time redirecting the output from here and there. So I did something else - a build task calling a *bat* file which calls the entry-point script. And yes, cleanup tasks in the definition as well. Everything is now OK. Still, will mark this one as a top clue. Thank you! – Ivaylo Angelov Apr 21 '17 at 21:28
0

There is the Continue on error option (Control Options section). The build process will be continued if it is true (checked), but the build result will be partially succeeded.

You also can output the error or warning by using PowerShell or VSTS task commands (uncheck Fail on Standard Error option in the Advanced section) and terminate the current PowerShell process by using the exit keyword, for example:

Write-Warning “warning”
Write-Error “error”
Write-Host " ##vso[task.logissue type=warning;]this is the warning"
Write-Host " ##vso[task.logissue type=error;sourcepath=consoleapp/main.cs;linenumber=1;columnnumber=1;code=100;]this is an error "

More information about the VSTS task command, you can refer to: Logging Commands

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • The task itself is green, it is running just fine - no errors. I need to somehow prevent it from closing everything that was started under the hood while it was running because next tasks depend on this setup. – Ivaylo Angelov Apr 06 '17 at 08:23
  • @lvayloangelov Could you provide the details of that scenario (e.g. scripts, workflow, result etc...) – starian chen-MSFT Apr 06 '17 at 08:48
  • Thanks for the reply and your activity on this one. I've added some more details in the question itself. – Ivaylo Angelov Apr 06 '17 at 12:19