-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from samsmithnz/feature/armtemplates3
Added AzureResourceManagerTemplateDeployment@3 task support
- Loading branch information
Showing
2 changed files
with
87 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ public GitHubActions.Step ProcessStep(AzurePipelines.Step step) | |
gitHubStep = CreateAzurePowershellStep(step); | ||
break; | ||
case "AZURERESOURCEGROUPDEPLOYMENT@2": | ||
case "AZURERESOURCEMANAGERTEMPLATEDEPLOYMENT@3": | ||
gitHubStep = CreateAzureManageResourcesStep(step); | ||
break; | ||
case "AZUREFUNCTIONAPP@1": | ||
|
@@ -1005,15 +1006,39 @@ private GitHubActions.Step CreateAzureManageResourcesStep(AzurePipelines.Step st | |
// csmParametersFile: '$(build.artifactstagingdirectory)/drop/ARMTemplates/azuredeploy.parameters.json' | ||
// overrideParameters: '-environment $(AppSettings.Environment) -locationShort $(ArmTemplateResourceGroupLocation)' | ||
|
||
|
||
//or: | ||
//- task: AzureResourceManagerTemplateDeployment@3 | ||
// inputs: | ||
// deploymentScope: 'Resource Group' | ||
// azureResourceManagerConnection: 'copy-connection' | ||
// subscriptionId: '00000000-0000-0000-0000-000000000000' | ||
// action: 'Create Or Update Resource Group' | ||
// resourceGroupName: 'demogroup' | ||
// location: 'West US' | ||
// templateLocation: 'URL of the file' | ||
// csmFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.json$(AzureFileCopy.StorageContainerSasToken)' | ||
// csmParametersFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.parameters.json$(AzureFileCopy.StorageContainerSasToken)' | ||
// deploymentMode: 'Incremental' | ||
// deploymentName: 'deploy1' | ||
|
||
// https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-cli | ||
//- name: Swap web service staging slot to production | ||
// uses: Azure/[email protected] | ||
// with: | ||
// inlineScript: az deployment group create --resource-group <resource-group-name> --template-file <path-to-template> | ||
|
||
string resourceGroup = GetStepInput(step, "resourcegroupname"); | ||
string armTemplateFile = GetStepInput(step, "csmfile"); | ||
string armTemplateParametersFile = GetStepInput(step, "csmparametersfile"); | ||
string resourceGroup = GetStepInput(step, "resourceGroupName"); | ||
string armTemplateFile = GetStepInput(step, "csmFile"); | ||
string armTemplateParametersFile = GetStepInput(step, "csmParametersFile"); | ||
if (string.IsNullOrEmpty(armTemplateFile) == true) | ||
{ | ||
armTemplateFile = GetStepInput(step, "csmFileLink"); | ||
} | ||
if (string.IsNullOrEmpty(armTemplateFile) == true) | ||
{ | ||
armTemplateParametersFile = GetStepInput(step, "csmParametersFileLink"); | ||
} | ||
string overrideParameters = GetStepInput(step, "overrideParameters"); | ||
|
||
string script = "az deployment group create --resource-group " + resourceGroup + | ||
|
@@ -2551,23 +2576,6 @@ public GitHubActions.Step[] AddSupportingSteps(AzurePipelines.Step[] steps, bool | |
} | ||
break; | ||
|
||
//If we have an Azure step, we will need to add a Azure login step | ||
case "AZURECLI@2": | ||
case "AZUREPOWERSHELL@4": | ||
case "AZUREAPPSERVICEMANAGE@0": | ||
case "AZURERESOURCEGROUPDEPLOYMENT@2": | ||
case "AZUREFUNCTIONAPP@1": | ||
case "AZUREFUNCTIONAPPCONTAINER@1": | ||
case "AZURERMWEBAPPDEPLOYMENT@3": | ||
case "AZURERMWEBAPPDEPLOYMENT@4": | ||
case "AZUREWEBAPPCONTAINER@1": | ||
case "AZUREWEBAPP@1": | ||
if (addAzureLoginStep == false) | ||
{ | ||
addAzureLoginStep = true; | ||
stepAdjustment++; | ||
} | ||
break; | ||
|
||
case "VSBUILD@1": | ||
if (addMSSetupStep == false) | ||
|
@@ -2576,6 +2584,30 @@ public GitHubActions.Step[] AddSupportingSteps(AzurePipelines.Step[] steps, bool | |
stepAdjustment++; | ||
} | ||
break; | ||
|
||
default: | ||
//If we have an Azure step, we will need to add a Azure login step | ||
if (step.task.ToUpper().StartsWith("AZURE") == true) | ||
{ | ||
//case "AZURECLI@2": | ||
//case "AZUREPOWERSHELL@4": | ||
//case "AZUREAPPSERVICEMANAGE@0": | ||
//case "AZURERESOURCEGROUPDEPLOYMENT@2": | ||
//case "AZURERESOURCEMANAGERTEMPLATEDEPLOYMENT@3": | ||
//case "AZUREFUNCTIONAPP@1": | ||
//case "AZUREFUNCTIONAPPCONTAINER@1": | ||
//case "AZURERMWEBAPPDEPLOYMENT@3": | ||
//case "AZURERMWEBAPPDEPLOYMENT@4": | ||
//case "AZUREWEBAPPCONTAINER@1": | ||
//case "AZUREWEBAPP@1": | ||
if (addAzureLoginStep == false) | ||
{ | ||
addAzureLoginStep = true; | ||
stepAdjustment++; | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1552,6 +1552,41 @@ public void ArmTemplateDeploymentStepTest() | |
Assert.AreEqual(expected, gitHubOutput.actionsYaml); | ||
} | ||
|
||
[TestMethod] | ||
public void ArmTemplateV3DeploymentStepTest() | ||
{ | ||
//Arrange | ||
Conversion conversion = new Conversion(); | ||
string yaml = @" | ||
- task: AzureResourceManagerTemplateDeployment@3 | ||
inputs: | ||
deploymentScope: 'Resource Group' | ||
azureResourceManagerConnection: 'copy-connection' | ||
subscriptionId: '00000000-0000-0000-0000-000000000000' | ||
action: 'Create Or Update Resource Group' | ||
resourceGroupName: $(ResourceGroupName) | ||
location: 'West US' | ||
templateLocation: 'URL of the file' | ||
csmFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.json$(AzureFileCopy.StorageContainerSasToken)' | ||
csmParametersFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.parameters.json$(AzureFileCopy.StorageContainerSasToken)' | ||
deploymentMode: 'Incremental' | ||
deploymentName: 'deploy1' | ||
overrideParameters: '-environment $(AppSettings.Environment) -locationShort $(ArmTemplateResourceGroupLocation)' | ||
"; | ||
|
||
//Act | ||
ConversionResponse gitHubOutput = conversion.ConvertAzurePipelineTaskToGitHubActionTask(yaml); | ||
|
||
//Assert | ||
string expected = @" | ||
- uses: Azure/[email protected] | ||
with: | ||
inlineScript: az deployment group create --resource-group ${{ env.ResourceGroupName }} --template-file ${{ env.AzureFileCopy.StorageContainerUri }}templates/mainTemplate.json${{ env.AzureFileCopy.StorageContainerSasToken }} --parameters -environment ${{ env.AppSettings.Environment }} -locationShort ${{ env.ArmTemplateResourceGroupLocation }} | ||
"; | ||
expected = UtilityTests.TrimNewLines(expected); | ||
Assert.AreEqual(expected, gitHubOutput.actionsYaml); | ||
} | ||
|
||
|
||
// [TestMethod] | ||
// public void MSBuildStepTest() | ||
|