0

I have a Node.js web server which, as part of a CD process, I want to deploy to a staging server using Azure Release Pipeline. The problem is, that if I just run a Powershell script:

# Run-Server.ps1
node my-server.js

The Pipeline will hold since the node process blocks the Powershell session. What I want is to be able to launch the service, and then in the next deployment just kill the node process and run it again with the new code.

So I figured I'll use Start-Process. If I run it locally:

> Start-Process node -ArgumentList ./server.js

I can now exit the Powershell session and the server will continue running. So I thought I can implement it the same way in my Release Pipeline.

But it turns out that once the Release Pipeline ends running, the server is no longer available - the node process is gone.

Can you help me figure out why is that? Is there another way of achieving this? I suppose it's a pretty common use case so there must be best-practices out there regarding to how this should be done.

5
  • Why would you want to run this app as apart of your pipeline? Commented Sep 9, 2021 at 11:23
  • @KrzysztofMadej - I think it's a pretty common use case to deploy your application to a staging environment so you can test it, before you deploy it to production. The docs about Release Pipelines are filled with this. Commented Sep 9, 2021 at 11:31
  • Yes, but pipeline infrastracture is not your staging environment and as far I understood what you wrote you try to run it on the build agent. Commented Sep 9, 2021 at 11:33
  • I try to run it on a server configured in a Deployment Group Commented Sep 9, 2021 at 11:53
  • Ok. Got it. Sorry for misunderstanding. Commented Sep 9, 2021 at 11:57

2 Answers 2

2

Another way to achieve this is to use a full-blown web server to host andmanage node process. I.e. on Windows you could use IIS with iisnode module. This is more reliable and gives you a few other benefits:

  • process management (automatic start, restart on failure, etc.)
  • security - you can configure the user that node process will run as
  • scalability on multi-core CPUs

Then the process of app deployment would be just copying files to the right directory - the web server should pick up the change automatically.

Sign up to request clarification or add additional context in comments.

Comments

1

By default, A pipeline job cleans up all of the child processes it spins up when it exits. This is killing your node server.

Set Process.Clean variable to false to override the default behavior.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.