Skip to content

Commit a59ae3d

Browse files
authored
Add -Force parameter on Publish-AzBicepModule (#21713)
1 parent 8334a14 commit a59ae3d

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

src/Resources/ResourceManager/Implementation/Bicep/PublishAzureBicepModuleCmdlet.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ public class PublishAzureBicepModuleCmdlet : AzureRMCmdlet
3333
[Parameter(Mandatory = false, HelpMessage = "Documentation uri of the Bicep module.")]
3434
public string DocumentationUri { get; set; }
3535

36+
[Parameter(Mandatory = false, HelpMessage="Overwrite existing published module.")]
37+
public SwitchParameter Force { get; set; }
38+
3639
[Parameter(Mandatory = false, HelpMessage="Indicates that this cmdlet returns a boolean result. By default, this cmdlet does not generate any output.")]
3740
public SwitchParameter PassThru { get; set; }
3841

3942
public override void ExecuteCmdlet()
4043
{
41-
BicepUtility.PublishFile(this.TryResolvePath(this.FilePath), this.Target, this.DocumentationUri, this.WriteVerbose, this.WriteWarning);
44+
BicepUtility.PublishFile(this.TryResolvePath(this.FilePath), this.Target, this.DocumentationUri, this.Force.IsPresent, this.WriteVerbose, this.WriteWarning);
4245

4346
if (this.PassThru.IsPresent)
4447
{

src/Resources/ResourceManager/Utilities/BicepUtility.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ internal static class BicepUtility
3232

3333
private const string MinimalVersionRequirementForBicepPublishWithOptionalDocumentationUriParameter = "0.14.46";
3434

35+
private const string MinimalVersionRequirementForBicepPublishWithOptionalForceParameter = "0.17.1";
36+
3537
private const string MinimalVersionRequirementForBicepparamFileBuild = "0.16.1";
3638

3739
public delegate void OutputCallback(string msg);
@@ -84,24 +86,26 @@ public static string BuildParamFile(string bicepParamFilePath, OutputCallback wr
8486
return buildResultPath;
8587
}
8688

87-
public static void PublishFile(string bicepFilePath, string target, string documentationUri = null, OutputCallback writeVerbose = null, OutputCallback writeWarning = null)
89+
public static void PublishFile(string bicepFilePath, string target, string documentationUri = null, bool force = false, OutputCallback writeVerbose = null, OutputCallback writeWarning = null)
8890
{
8991
if (!FileUtilities.DataStore.FileExists(bicepFilePath))
9092
{
9193
throw new AzPSArgumentException(Properties.Resources.InvalidBicepFilePath, "File");
9294
}
9395

94-
string bicepPublishCommand;
95-
96+
string bicepPublishCommand = $"bicep publish '{bicepFilePath}' --target '{target}'";
9697
if (!string.IsNullOrWhiteSpace(documentationUri))
9798
{
9899
CheckMinimalVersionRequirement(MinimalVersionRequirementForBicepPublishWithOptionalDocumentationUriParameter);
99-
bicepPublishCommand = $"bicep publish '{bicepFilePath}' --target '{target}' --documentationUri '{documentationUri}'";
100+
bicepPublishCommand += $" --documentationUri '{documentationUri}'";
100101
}
101-
else
102+
103+
if (force)
102104
{
103-
bicepPublishCommand = $"bicep publish '{bicepFilePath}' --target '{target}'";
105+
CheckMinimalVersionRequirement(MinimalVersionRequirementForBicepPublishWithOptionalForceParameter);
106+
bicepPublishCommand += $" --force";
104107
}
108+
105109

106110
RunBicepCommand(bicepPublishCommand, MinimalVersionRequirementForBicepPublish, writeVerbose, writeWarning);
107111
}

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added `-Force` parameter on `Publish-AzBicepModule` for supporting overwriting existing modules.
2223
* Fixed `New-AzADApplication` when multiple redirect url types are provided. [#21108]
2324
* Fixed `Update-AzADServicePrincipal` when empty array passed for `IdentifierUri` [#21345]
2425
* Fixed an issue where location header was missing in the response from the service for New-AzManagedApplication.

src/Resources/Resources/help/Publish-AzBicepModule.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Publishes a Bicep file to a registry.
1313
## SYNTAX
1414

1515
```
16-
Publish-AzBicepModule -FilePath <String> -Target <String> [-DocumentationUri <String>] [-PassThru]
16+
Publish-AzBicepModule -FilePath <String> -Target <String> [-DocumentationUri <String>] [-Force] [-PassThru]
1717
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1818
```
1919

@@ -29,6 +29,13 @@ Publish-AzBicepModule -FilePath 'main.bicep' -Target 'br:{registry}/{moduleName}
2929

3030
Publishes `main.bicep` to `br:{registry}/{moduleName}:{tag}`.
3131

32+
### Example 2
33+
```powershell
34+
Publish-AzBicepModule -FilePath 'main.bicep' -Target 'br:{registry}/{moduleName}:{tag}' -Force
35+
```
36+
37+
Publishes `main.bicep` to `br:{registry}/{moduleName}:{tag}`, overwriting existing version.
38+
3239
## PARAMETERS
3340

3441
### -DefaultProfile
@@ -75,6 +82,20 @@ Default value: None
7582
Accept pipeline input: True (ByPropertyName)
7683
Accept wildcard characters: False
7784
```
85+
### -Force
86+
Allows overwriting of existing module.
87+
88+
```yaml
89+
Type: System.Management.Automation.SwitchParameter
90+
Parameter Sets: (All)
91+
Aliases:
92+
93+
Required: False
94+
Position: Named
95+
Default value: None
96+
Accept pipeline input: False
97+
Accept wildcard characters: False
98+
```
7899
79100
### -PassThru
80101
Indicates that this cmdlet returns a boolean result. By default, this cmdlet does not generate any output.

0 commit comments

Comments
 (0)