Last active
May 11, 2021 05:34
-
-
Save clemp6r/08c46ff5fea917ff23c0 to your computer and use it in GitHub Desktop.
Gradle task for deploying a file to Azure Blob Storage
This file contains 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 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
@GokhanArik did you get a response or resolution for this? I need to push a file to azure blob storage after every build..