Skip to content

Instantly share code, notes, and snippets.

@samuraitruong
Created May 4, 2018 03:48
Show Gist options
  • Save samuraitruong/6387b8f9665f8d7fc421de1c06754fb8 to your computer and use it in GitHub Desktop.
Save samuraitruong/6387b8f9665f8d7fc421de1c06754fb8 to your computer and use it in GitHub Desktop.
Azure deploy webjob
# Set the Azure Subscription in current PowerShell context.
function setAzureSubscription($basePath){
# run Get-AzurePublishSettingsFile to retrive the file
$path = '{0}/{1}' -f $basePath, 'samuraitruong.PublishSettings'
# write-host (Get-Content -path $path)
Import-AzurePublishSettingsFile -PublishSettingsFile $path | Out-Null
Select-AzureSubscription -SubscriptionName "Pay-As-You-Go" | Out-Null
Write-Host "$(Get-Date -f $timeStampFormat) - Set Azure subscription Completed " -foregroundcolor "green"
}
# Build the console application using DotNet CLI.
function build($basePath){
$path = '{0}/{1}' -f $basePath, 'bin'
#Get-ChildItem -Path $path -Include *.* -File -Recurse | foreach { $_.Delete()}
#Write-Host "$(Get-Date -f $timeStampFormat) - Bin Directory Completed " -foregroundcolor "green"
# dotnet build --configuration release $basePath | Out-Null
# Write-Host "$(Get-Date -f $timeStampFormat) - Dotnet Build Completed " -foregroundcolor "green"
Remove-Item -Path ($path +"/Release.zip" )
}
# Create the ZIP package using System.IO API.
function createPackage($basePath){
$path = '{0}/{1}' -f $basePath, 'bin\Release'
$zipPath = '{0}/{1}' -f $basepath, 'bin\Release.zip'
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($path, $zipPath,
$compressionLevel,
$false)
Write-Host "$(Get-Date -f $timeStampFormat) - Zip Package Created " -foregroundcolor "green"
}
# Deploy the ZIP Package to AzureWebsite using New-AzureWebsiteJob cmdlet.
function deploy($webSite, $jobName, $jobType, $basepath){
$zipPath = '{0}/{1}' -f $basepath, 'bin\Release.zip'
New-AzureWebsiteJob -Name $webSite -JobName $jobName -JobType $jobType -JobFile $zipPath | Out-Null
Write-Host "$(Get-Date -f $timeStampFormat) - Completed Deployment " -foregroundcolor "green"
}
#Invoke all the above created functions
function execute($webSite, $jobName, $jobType, $basePath){
setAzureSubscription $basePath
build $basePath
createPackage $basePath
deploy $webSite $jobName $jobType $basepath
}
execute "RankScheduleWebJob" "test123schedule" "Triggered" "C:\Users\Truong.Nguyen\Desktop\AzurePS-CI\samplejob"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment