Service Name is not showing in Services Console EC2 Windows instance

1

Hi AWS, I am creating windows application as service using CI/CD written in GitHub Actions which is configured on EC2 Windows machine. The issue is weird as the command is getting executed successfully but when I am checking the service name in the Services console it is not showing. I have also refreshed the screen but no luck.

Here is the pipeline code:

name: "Deploying a CI/CD for .NET sample app using GitHub Actions and storing the application artifacts to Amazon S3"

on:
  workflow_dispatch:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: [ self-hosted, Windows, X64 ]
    defaults:
      run:
        shell: cmd

    steps:
    - name: Checkout code repository
      uses: actions/checkout@v3
      
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '7.0'
        include-prerelease: True
        
    - name: Print dotnet version
      run: dotnet --version
    - name: Restore dependencies
      run: dotnet restore
      
    # dotnet build and publish
    - name: Build with dotnet
      run: dotnet build --configuration Release  
    - name: Publish the artifacts
      run: dotnet publish -c Release -o ./publish
      
    # IIS Deployment
    - name: Deploy to IIS Server
      shell: powershell
      run: |
        Start-Process powershell -ArgumentList "iisreset /stop" -Verb RunAs
        Copy-Item ./publish/* C:/inetpub/wwwroot/ -Recurse -Force
        # Start-Process powershell -ArgumentList 'Copy-Item ./publish/*.exe C:/Windows/System32 -Recurse -Force' -Verb RunAs
        Start-Process powershell -ArgumentList "iisreset /start" -Verb RunAs
    - name: Zip the publish folder
      shell: powershell
      run: Compress-Archive ./publish/* output.zip

   # Push artifacts to S3 bucket
    - name: Set AWS credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: ${{ secrets.AWS_REGION }}
        
    - name: Uploading the application artifacts to Amazon S3
      shell: cmd
      run: C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp output.zip s3://dotnet-cicd-bucket/

  windows-service:
    needs: build
    runs-on: [ self-hosted, Windows, X64 ]
    defaults:
      run:
        shell: cmd

    steps:
    # Run the application as Windows Service
    - name: Create the windows service
      shell: powershell
      run: Start-Process powershell -ArgumentList "C:\Windows\System32 sc.exe 'EC2AMAZ-6UI1SRT' create 'MyWebApp' binpath= 'c:\inetpub\wwwroot\*.exe'" -Verb RunAs
        
    - name: Curl the website 
      run: curl http://localhost/

Am I missing something, like enable some option settings? Please help

profile picture
Arjun
asked 7 months ago238 views
1 Answer
0

Here is the new code I have written for the same, but still the same issue persists. Any idea:

name: "Deploying a CI/CD for Windows Service using GitHub Actions"

on:
  workflow_dispatch:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

      runs-on: windows-latest
      defaults:
        run:
          shell: cmd

      steps:
      - name: Checkout code repository
        uses: actions/checkout@v3
      
      - name: Setup MSBuild
        uses: microsoft/setup-msbuild@v1

      - name: Setup NuGet
        uses: NuGet/setup-nuget@v1.0.5

      - name: Restore Packages
        run: nuget restore WindowsServiceDemo.sln

      - name: Build solution
        run: msbuild WindowsServiceDemo.sln /p:Configuration=Release /p:DeployOnBuild=true

  deploy:
    needs: build
    runs-on: [ self-hosted, Windows, X64 ]
    defaults:
      run:
        shell: cmd
    
    steps:
    
     - name: Set AWS credentials
       uses: aws-actions/configure-aws-credentials@v1
       with:
         aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
         aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
         aws-region: ${{ secrets.AWS_REGION }}
         
     - name: Install a service using Powershell
       shell: powershell
       run: Start-Process powershell -ArgumentList 'New-Service -Name "WinServDemo" -BinaryPathName "D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.exe"' -Verb RunAs

     - name: Start a service using Poweshell
       shell: powershell
       run: Start-Process powershell -ArgumentList 'Start-Service -Name "WinServDemo"' -Verb RunAs

     - name: Display the service status
       shell: powershell
       run: Start-Process powershell Get-Service -Verb RunAs

The build job is running on GitHub self-hosted runner and the deploy job is running on EC2 Windows instance as self-hosted runner. The instance type is t2.micro using Base Windows Image 2022.

profile picture
Arjun
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions