Skip to content

Commit d5d6c7f

Browse files
authored
Merge pull request #106 from postsharp/topic/2023.1/fix-git-identity
Git identity should not flow from TeamCity agent to docker build.
2 parents 4be542a + c077ee1 commit d5d6c7f

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

DockerBuild.ps1

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,21 @@ if (-not $KeepEnv)
145145
}
146146

147147
# Add git identity to environment
148-
$env:GIT_USER_EMAIL = git config --global user.email
149-
$env:GIT_USER_NAME = git config --global user.name
150-
151148
if ($env:IS_TEAMCITY_AGENT)
152149
{
153-
if (-not $env:GIT_USER_EMAIL)
154-
{
155-
$env:GIT_USER_EMAIL = '[email protected]'
156-
}
157-
if (-not $env:GIT_USER_NAME)
150+
# On TeamCity agents, check if the environment variables are set.
151+
if (-not $env:GIT_USER_EMAIL -or -not $env:GIT_USER_NAME)
158152
{
159-
$env:GIT_USER_NAME = 'teamcity'
153+
Write-Error "On TeamCity agents, the GIT_USER_EMAIL and GIT_USER_NAME environment variables must be set."
154+
exit 1
160155
}
161156
}
157+
else
158+
{
159+
# On developer machines, use the current git user.
160+
$env:GIT_USER_EMAIL = git config --global user.email
161+
$env:GIT_USER_NAME = git config --global user.name
162+
}
162163

163164
New-EnvJson -EnvironmentVariableList $EnvironmentVariables
164165
}

src/PostSharp.Engineering.BuildTools/Resources/DockerBuild.ps1

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,21 @@ if (-not $KeepEnv)
145145
}
146146

147147
# Add git identity to environment
148-
$env:GIT_USER_EMAIL = git config --global user.email
149-
$env:GIT_USER_NAME = git config --global user.name
150-
151148
if ($env:IS_TEAMCITY_AGENT)
152149
{
153-
if (-not $env:GIT_USER_EMAIL)
154-
{
155-
$env:GIT_USER_EMAIL = '[email protected]'
156-
}
157-
if (-not $env:GIT_USER_NAME)
150+
# On TeamCity agents, check if the environment variables are set.
151+
if (-not $env:GIT_USER_EMAIL -or -not $env:GIT_USER_NAME)
158152
{
159-
$env:GIT_USER_NAME = 'teamcity'
153+
Write-Error "On TeamCity agents, the GIT_USER_EMAIL and GIT_USER_NAME environment variables must be set."
154+
exit 1
160155
}
161156
}
157+
else
158+
{
159+
# On developer machines, use the current git user.
160+
$env:GIT_USER_EMAIL = git config --global user.email
161+
$env:GIT_USER_NAME = git config --global user.name
162+
}
162163

163164
New-EnvJson -EnvironmentVariableList $EnvironmentVariables
164165
}

0 commit comments

Comments
 (0)