-
-
Save jmacias/d4ca87d6f9afe91ebf89 to your computer and use it in GitHub Desktop.
Gradle task for deploying a file to Azure Blob Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.clemp6r.azuregradle | |
import org.gradle.api.DefaultTask | |
import com.microsoft.azure.storage.*; | |
import com.microsoft.azure.storage.blob.* | |
import org.gradle.api.tasks.TaskAction; | |
class AzureStorageDeployTask extends DefaultTask { | |
String connectionString | |
String container | |
String fileToDeploy | |
@TaskAction | |
def deploy() { | |
checkArguments() | |
CloudStorageAccount account = CloudStorageAccount.parse(connectionString); | |
CloudBlobClient serviceClient = account.createCloudBlobClient(); | |
CloudBlobContainer blobContainer = serviceClient.getContainerReference(container); | |
blobContainer.createIfNotExists(); | |
def file = project.file(fileToDeploy) | |
CloudBlockBlob blob = blobContainer.getBlockBlobReference(file.name); | |
blob.upload(new FileInputStream(file), file.length()); | |
} | |
private void checkArguments() { | |
if (!connectionString) { | |
throw new IllegalArgumentException("The 'connectionString' property is missing"); | |
} | |
if (!container) { | |
throw new IllegalArgumentException("The 'container' property is missing"); | |
} | |
if (!fileToDeploy) { | |
throw new IllegalArgumentException("The 'fileToDeploy' property is missing"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile 'com.microsoft.azure:azure-storage:2.0.0' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment