Skip to content

Commit 5b01c18

Browse files
Update profile.ps1 template for PowerShell function apps. (#6327)
1 parent 073bc5d commit 5b01c18

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

src/WebJobs.Script/FileProvisioning/PowerShell/profile.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
#
99
# You can define helper functions, run commands, or specify environment variables
1010
# NOTE: any variables defined that are not environment variables will get reset after the first execution
11+
1112
# Authenticate with Azure PowerShell using MSI.
1213
# Remove this if you are not planning on using MSI or Azure PowerShell.
13-
14-
if ($env:MSI_SECRET -and (Get-Module -ListAvailable Az.Accounts)) {
15-
    Connect-AzAccount -Identity
14+
if ($env:MSI_SECRET) {
15+
Disable-AzContextAutosave
16+
Connect-AzAccount -Identity
1617
}
1718

1819
# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
1920
# Enable-AzureRmAlias
21+
2022
# You can also define functions or aliases that can be referenced in any of your PowerShell functions.

test/WebJobs.Script.Tests/FileProvisioning/PowerShellFileProvisionerTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class PowerShellFileProvisionerTests
3131
private const string PSGalleryEmptyFeedResourceFileName =
3232
"Microsoft.Azure.WebJobs.Script.Tests.Resources.FileProvisioning.PowerShell.PSGalleryEmptyFeed.xml";
3333

34+
private const string ProfileFileResourceFileName =
35+
"Microsoft.Azure.WebJobs.Script.Tests.Resources.FileProvisioning.PowerShell.profile.ps1";
36+
3437
private readonly string _scriptRootPath;
3538
private readonly ILoggerFactory _loggerFactory = new LoggerFactory();
3639
private readonly TestLoggerProvider _loggerProvider = new TestLoggerProvider();
@@ -57,6 +60,10 @@ public async Task AugmentFiles_Test()
5760
string expectedContent = FileUtility.ReadResourceString(RequirementsPsd1PSGalleryOnlineResourceFileName);
5861
Assert.Equal(expectedContent, requirementsContent, StringComparer.OrdinalIgnoreCase);
5962

63+
string profileContent = File.ReadAllText(Path.Combine(_scriptRootPath, ProfilePs1FileName));
64+
string expectedProfileContent = FileUtility.ReadResourceString(ProfileFileResourceFileName);
65+
Assert.Equal(expectedProfileContent, profileContent, StringComparer.OrdinalIgnoreCase);
66+
6067
ValidateLogs(_loggerProvider, _scriptRootPath);
6168
}
6269

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Azure Functions profile.ps1
2+
#
3+
# This profile.ps1 will get executed every "cold start" of your Function App.
4+
# "cold start" occurs when:
5+
#
6+
# * A Function App starts up for the very first time
7+
# * A Function App starts up after being de-allocated due to inactivity
8+
#
9+
# You can define helper functions, run commands, or specify environment variables
10+
# NOTE: any variables defined that are not environment variables will get reset after the first execution
11+
12+
# Authenticate with Azure PowerShell using MSI.
13+
# Remove this if you are not planning on using MSI or Azure PowerShell.
14+
if ($env:MSI_SECRET) {
15+
Disable-AzContextAutosave
16+
Connect-AzAccount -Identity
17+
}
18+
19+
# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
20+
# Enable-AzureRmAlias
21+
22+
# You can also define functions or aliases that can be referenced in any of your PowerShell functions.

test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@
107107
<None Remove="Resources\FileProvisioning\PowerShell\PSGallerySampleFeed.xml" />
108108
<None Remove="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOffline.psd1" />
109109
<None Remove="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOnline.psd1" />
110+
<None Remove="Resources\FileProvisioning\PowerShell\profile.ps1" />
110111
</ItemGroup>
111112

112113
<ItemGroup>
113114
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\PSGallerySampleFeed.xml" />
114115
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\PSGalleryEmptyFeed.xml" />
115116
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOffline.psd1" />
116-
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOnline.psd1">
117+
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOnline.psd1"/>
118+
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\profile.ps1">
117119
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
118120
</EmbeddedResource>
119121
</ItemGroup>

0 commit comments

Comments
 (0)