我正在测试 Azure Powershell 函数应用程序。我使用 Azure DEvOps 管道将函数文件上传到 Azure Function App,管道成功完成,我可以在我的 Function App 主刀片 Function/App 文件中看到 run.ps1 和 function.json 这两个文件。我的文件如下:
运行.ps1
# Input bindings are passed in via param block.
param($Timer)
# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()
# The 'IsPastDue' property is 'true' when the current function invocation is later than scheduled.
if ($Timer.IsPastDue) {
Write-Host "PowerShell timer is running late!"
}
# Write an information log with the current time.
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime"
函数.json
{
"bindings": [
{
"name": "Timer",
"type": "timerTrigger",
"direction": "in",
"schedule": "* * * * * *"
}
]
}
我不确定如何根据这些文件创建函数,当我转到
Overview
时,我在 Functions
选项卡中看不到任何函数。没有使用选项 Develop in Portal
创建函数的选项。我在 MS 文档中没有找到任何有用的信息。早些时候,当我使用 Develop in the Portal
选项时,我能够从门户手动创建函数应用程序。现在,当我使用 Azure DevOps 管道将函数文件(run.ps1、function.json)上传到 Azure Function App 时,我不确定创建函数的推荐方法。
它会要求您选择订阅,在Azure Portal上创建的Function App。
下面是自动创建的管道的 YAML 代码 :
trigger:
- main
variables:
azureSubscription: '<subscription_id>'
functionAppName: 'dkazfnapp-ci-101'
vmImageName: 'windows-2019'
workingDirectory: '$(System.DefaultWorkingDirectory)/'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- powershell: |
if (Test-Path "extensions.csproj") {
dotnet build extensions.csproj --output ./$(workingDirectory)/bin
}
displayName: 'Build extensions'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: $(workingDirectory)
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: $(functionAppName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionApp
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
有关管道定制的更多信息,请参阅此MS文档。
保存并运行管道。
点击“查看”和“许可”部署功能应用程序。
6. 部署成功:
结果: