Automate .NET Core Deployments to Windows Server using Bitbucket Pipelines

Image for post
Image for post
source: https://www.synopsys.com/glossary/what-is-cicd.html
  • Configured SSH on your server
  • Generated SSH keys and copied public key on server
  • Your project is in a Bitbucket repository
  • You have pipelines enabled in your repository settings
image:  mcr.microsoft.com/dotnet/core/sdk:3.1
image:  mcr.microsoft.com/dotnet/core/sdk:3.1pipelines:
default:
- step:
name: Build App
caches:
- dotnetcore
script:
- dotnet restore
- dotnet build --no-restore
- dotnet publish --no-restore -c Release -o $BITBUCKET_CLONE_DIR/release
artifacts:
- release/**
branches:
master:
- step:
image:  mcr.microsoft.com/dotnet/core/sdk:3.1pipelines:
default:
- step:
name: Build App
caches:
- dotnetcore
script:
- dotnet restore
- dotnet build --no-restore
- dotnet publish --no-restore -c Release -o $BITBUCKET_CLONE_DIR/release
artifacts:
- release/**
#2nd step to deploy to the server
- step:
name: Deploy to server
deployment: staging
script:
- pipe: atlassian/scp-deploy:0.3.9
variables:
USER: $USER
SERVER: $SERVER
REMOTE_PATH: $REMOTE_PATH
LOCAL_PATH: 'release/*'
DEBUG: 'true'
  • SERVER is the IP or URL to your server
  • REMOTE_PATH is the path that you want to copy your files to on the server and must exist prior to running the pipeline
  • LOCAL_PATH is the path that has the files we need to copy over. In this case, simply put the relative path to the artifact we produced in the previous step
  • DEBUG is optional and set to false by default, but I keep it true while working on the pipeline
image:  mcr.microsoft.com/dotnet/core/sdk:3.1pipelines:
default:
- step:
name: Build App
caches:
- dotnetcore
script:
- dotnet restore
- dotnet build --no-restore
- dotnet publish --no-restore -c Release -o $BITBUCKET_CLONE_DIR/release
artifacts:
- release/**
#2nd step to deploy to the server
- step:
name: Deploy to server
deployment: staging
script:
- pipe: atlassian/scp-deploy:0.3.9
variables:
USER: $USER
SERVER: $SERVER
REMOTE_PATH: $REMOTE_PATH
LOCAL_PATH: 'release/*'
DEBUG: 'true'
#3rd step runs script on server
- step:
name: Run batch script
caches:
- docker
script:
- pipe: docker://accessefm/bat-script-runner:latest
variables:
HOST: $SERVER
USER: $USER
PORT: $PORT
SCRIPT_REMOTE_PATH: $DEPLOY_SCRIPT_PATH
ARGUMENTS: '$SRC $DEST'

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store