variables:
publish_path: '.\DotNetDocs\publish\$CI_PIPELINE_ID\'
published_data_path: '.\DotNetDocs\publish\$CI_PIPELINE_ID\*.*'
application_pool_name: 'FarhadZamani'
iis_worker_path: 'C:\Publish\FarhadZamani'
stages:
- build
- tests
- deploy
build:
stage: build
script:
- dotnet restore
- dotnet build --no-restore
- dotnet publish .\DotNetDocs\DotNetDocs.csproj -c Release -o $publish_path
artifacts:
paths:
- $publish_path
expire_in: '1 hrs'
tags:
- dotnet
only:
- develop
- master
unit-test:
stage: tests
script:
- dotnet test --no-build --verbosity normal
tags:
- dotnet
only:
- master
- develop
needs: [build]
production:
stage: deploy
script:
- |
if((Get-WebSiteState -Name $application_pool_name).Value -ne 'Stopped'){
Write-Output ('Stopping WebSite: {0}' -f $application_pool_name)
Stop-WebSite -Name $application_pool_name
}
- |
if((Get-WebAppPoolState -Name $application_pool_name).Value -ne 'Stopped'){
Write-Output ('Stopping Application Pool: {0}' -f $application_pool_name)
Stop-WebAppPool -Name $application_pool_name
}
- "Copy-Item $published_data_path -Destination $iis_worker_path -Force"
- "Start-Sleep -s 5"
- |
if((Get-WebAppPoolState -Name $application_pool_name).Value -ne 'Started'){
Write-Output ('Starting Application Pool: {0}' -f $application_pool_name)
Start-WebAppPool -Name $application_pool_name
}
- |
if((Get-WebSiteState -Name $application_pool_name).Value -ne 'Started'){
Write-Output ('Starting WebSite: {0}' -f $application_pool_name)
Start-WebSite -Name $application_pool_name
}
only:
- master
tags:
- dotnet
needs: [unit-test, build]
when: manual
dependencies:
- build