Skip to content

Commit a068ee6

Browse files
addign createby tag in pipeline
1 parent 9fa0039 commit a068ee6

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Deployment/main.bicep

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ var resourceGroupLocation = resourceGroup().location
2323
// Load the abbrevations file required to name the azure resources.
2424
var abbrs = loadJsonContent('./abbreviations.json')
2525

26-
var deployerInfo = deployer()
26+
@description('Optional created by user name')
27+
param createdBy string //= empty(deployer().userPrincipalName) ? '' : split(deployer().userPrincipalName, '@')[0]
2728

2829
resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = {
2930
name: 'default'
3031
properties: {
3132
tags: {
3233
TemplateName: 'DKM'
33-
CreatedBy: split(deployerInfo.userPrincipalName, '@')[0]
34+
CreatedBy: createdBy
3435
}
3536
}
3637
}
@@ -213,3 +214,5 @@ output gs_containerregistry_endpoint string = gs_containerregistry.outputs.acrEn
213214
//return resourcegroup resource ID
214215
output gs_resourcegroup_id string = resourceGroup().id
215216

217+
output createdByOutput string = createdBy
218+

Deployment/resourcedeployment.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function PromptForParameters {
8080
[string]$location,
8181
[string]$modelLocation,
8282
[string]$email
83-
)
83+
)
8484

8585
Clear-Host
8686

@@ -169,8 +169,9 @@ function LoginAzure([string]$subscriptionID) {
169169
az login --service-principal `
170170
--username $env:AZURE_CLIENT_ID `
171171
--password $env:AZURE_CLIENT_SECRET `
172-
--tenant $env:AZURE_TENANT_ID
172+
--tenant $env:AZURE_TENANT_ID `
173173
Write-Host "CI deployment mode"
174+
$createdBy = 'pipeline'
174175
}
175176
else{
176177
az login --tenant $tenantId
@@ -183,9 +184,10 @@ function LoginAzure([string]$subscriptionID) {
183184
Write-Host "Logged in to Azure with tenant ID '$tenantId' successfully." -ForegroundColor Green
184185
}
185186
Write-Host "manual deployment mode"
187+
$createdBy = $email
186188
}
187189
az account set --subscription $subscriptionID
188-
Write-Host "Switched subscription to '$subscriptionID' `r`n" -ForegroundColor Yellow
190+
Write-Host "Switched subscription to '$subscriptionID' `r`n" -ForegroundColor Yellow
189191
}
190192

191193
function DeployAzureResources([string]$location, [string]$modelLocation) {
@@ -246,7 +248,7 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
246248

247249
# Perform a what-if deployment to preview changes
248250
Write-Host "Evaluating Deployment resource availabilities to preview changes..." -ForegroundColor Yellow
249-
$whatIfResult = az deployment group what-if --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName
251+
$whatIfResult = az deployment group what-if --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName createdBy=$createdBy
250252

251253
if ($LASTEXITCODE -ne 0) {
252254
Write-Host "There might be something wrong with your deployment." -ForegroundColor Red
@@ -257,7 +259,7 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
257259
# Proceed with the actual deployment
258260
Write-Host "Proceeding with Deployment..." -ForegroundColor Yellow
259261
Write-Host "Resource Group Name: $resourceGroupName" -ForegroundColor Yellow
260-
$deploymentResult = az deployment group create --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName
262+
$deploymentResult = az deployment group create --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName createdBy=$createdBy
261263
# Check if deploymentResult is valid
262264
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult -variableName "Deployment Result"
263265
if ($LASTEXITCODE -ne 0) {

0 commit comments

Comments
 (0)