How stop service before execution

Hello,

How to stop windows service before the runner deletes files on the remote server ?

I try to stop my service in before_script but it doesn’t work.

Files are deleted before the before_script runs

Thank you.

stages:
    - build

buildTest:
    stage: build
    tags:
        - app-test
    before_script:
        - git config --system core.longpaths true
        - Stop-Service -Name "appService"
    script:
        - cp -r -fo "packages\app\.env.test" "packages\app\.env"
        - npm run bootstrap
        - npm run build
        - Start-Service -Name "appService"
    only:
        - dev

Hi @jcouturier

Stop-Service just sends the stop signal to the service. It does not actually wait for the service to be stopped. You need to implement some kind of loop to check the service is in Stopped state.

Ok thank you
and do you have any idea how to do that please?

It doesn’t work

before_script:
    - git config --system core.longpaths true
    - Stop-Service -Name "appService"
    - $service = Get-Service -Name 'appService'
        while ($service.Status -ne 'Stopped') { $service.Refresh() }

Really not a windows expert here but since you already have a service controller after Get-Service you could try this:

before_script:
    - git config --system core.longpaths true
    - Stop-Service -Name "appService"
    - |
      $service = Get-Service -Name 'appService'
      $service.WaitForStatus('Stopped')

See:

1 Like