Hi AWS, I am trying to deploy a windows service using CI/CD pipeline with the help of GitHub Actions. The Windows service is written in .NET Framework 4.7 with C#.
Here is the code repo: https://github.com/arjungoel/WindowsServiceDemo
Pipeline Code:
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
- 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: Upload the files from bin folder to S3 bucket
run: |
aws s3 cp D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.exe.config s3://dotnet-cicd-bucket/
aws s3 cp D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.exe s3://dotnet-cicd-bucket/
aws s3 cp D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.pdb s3://dotnet-cicd-bucket/
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: Download the zip file from S3 to EC2 folder
shell: powershell
run: |
C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp s3://dotnet-cicd-bucket/WindowsServiceDemo.exe "C:\actions-runner\_work"
C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp s3://dotnet-cicd-bucket/WindowsServiceDemo.exe.config "C:\actions-runner\_work"
C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp s3://dotnet-cicd-bucket/WindowsServiceDemo.pdb "C:\actions-runner\_work"
- name: Install a service using command prompt
shell: cmd
run: |
cd C:\Windows\System32 & "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" "C:\actions-runner\work\WindowsServiceDemo.exe"
# # - name: Display the service status
# shell: powershell
# run: Start-Process powershell Get-Service -Verb RunAs
The build
job is running on GitHub Hosted Runner and the deploy
job is running on Self-Hosted runner which is configured on Amazon EC2 Windows instance. Now the problem is at the installation step I am getting this error:
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\actions-runner\work\WindowsServiceDemo.exe' or one of its dependencies. The system cannot find the file specified..
Error: Process completed with exit code -1.
and I believe this is a general permission issue in windows but I am not aware of how to fix it. Is there something which I have to enable in the OS settings manually or any small change in the code can help me get rid off this issue. I have tried to find a post on Stack Overflow or YouTube but nothing helped and I have already spent more than 15 hours to get rid off this issue but no luck yet!
This issue is an extension to the issue already opened i.e. https://repost.aws/questions/QUmNS6bap2TIOiy_Ca6XpDog/windows-service-is-not-found-in-t2-micro-ec2-windows-instance
The instance size is not an issue as I have tried it with a larger instance size like t2.large
.
Please help as I need to fix this ASAP!
Hi Kirk_D, I have provided the solution below to get rid off the error.