Azure Function App - Azure DevOps 管道部署

问题描述 投票:0回答:1

我正在测试 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 azure-devops azure-functions azure-pipelines azure-powershell
1个回答
0
投票
  1. 当我们创建Azure Function App时,它会显示在Azure Portal中创建和开发的选项:

enter image description here

  1. 在 VS Code 中创建 PowerShell Core 计时器触发器 Azure Function App,并使用 git 命令将代码推送到 Azure DevOps 存储库:

enter image description here

  1. 单击“设置构建
  2. 它会带您管道作业步骤,其中自动选择存储库和分支。然后选择如下所示的选项:

enter image description here

它会要求您选择订阅,在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文档

保存并运行管道。

  1. 构建成功并要求授予部署权限:
    enter image description here

点击“查看”和“许可”部署功能应用程序。
6. 部署成功:

enter image description here

结果

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.