Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Web Jobs now get created during deploy if they do not already exist #1174

Merged
merged 1 commit into from
Mar 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion help/azurewebjobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

FAKE can be used to zip the output directory of a project and push it to Azure via the [zip controller](https://github.com/projectkudu/kudu/wiki/REST-API#zip).

You'll need to know the ftp details of the website to publish the web jobs to. Also the web jobs need to already exist on the azure dashboard.
You'll need to know the http authentication details of the website to publish the web jobs to. If the web job does not already exist, it will be created as part of the deploy.

In your `build.fsx` add the following:

Expand Down
16 changes: 10 additions & 6 deletions src/app/FakeLib/AzureWebJobs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System.IO
open System
open System.Net
open System.Collections.Generic
open System.Text

/// The running modes of webjobs
[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -70,13 +71,16 @@ let PackageWebJobs webSites =
webSites |> List.iter (fun webSite -> webSite.WebJobs |> List.iter (zipWebJob webSite))

let private deployWebJobToWebSite webSite webJob =
let uploadApi = Uri(webSite.Url, sprintf"api/zip/site/wwwroot/App_Data/jobs/%s/%s" (jobTypePath webJob.JobType) webJob.Name)
let uploadUri = Uri(webSite.Url, sprintf "api/%swebjobs/%s" (jobTypePath webJob.JobType) webJob.Name)
let filePath = webJob.PackageLocation
tracefn "Deploying %s webjob to %O" filePath uploadApi
use client = new WebClientWithTimeout()

client.Credentials <-NetworkCredential(webSite.UserName, webSite.Password)
client.UploadData(uploadApi,"PUT",File.ReadAllBytes(filePath)) |> ignore
tracefn "Deploying %s webjob to %O" filePath uploadUri
use client = new WebClientWithTimeout(Credentials = NetworkCredential(webSite.UserName, webSite.Password))

client.Headers.Add(HttpRequestHeader.ContentType, "application/zip")
client.Headers.Add("Content-Disposition", sprintf "attachment; filename=%s" (Path.GetFileName webJob.PackageLocation))

let response = client.UploadFile("https://tcappdev.scm.azurewebsites.net/api/continuouswebjobs/samplewebjob", "PUT", @"C:\Users\Isaac\Source\Repos\tag-functional\bin\webjobs\tcappdev.zip")
tracefn "Response from webjob upload: %s" (Encoding.ASCII.GetString response)

let private deployWebJobsToWebSite webSite =
webSite.WebJobs |> List.iter (deployWebJobToWebSite webSite)
Expand Down