更新:
是否可以添加或更改在Azure DevOps上执行管道的命令
在Visual Studio代码上本地运行我的程序时,我确实会得到输出
但是,在Azure DevOps上运行myGitHub源分支不会产生任何输出
我遵循了堆栈溢出answer,它将此解决方案引用到GitHub Issue
我已经实现了以下功能,但是Azure的原始日志在我的Python上返回空白logging
test_logging.py
:
import logging
filename = "my.log"
global logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
open(filename, "w").close() # empty logs
fileHandler = logging.FileHandler(filename)
fileHandler.setFormatter(formatter)
fileHandler.setLevel(logging.INFO)
logger.addHandler(fileHandler)
logger.error('TEST')
# fetch logs
with open(filename, "r") as fileHandler:
logs = [log.rstrip() for log in fileHandler.readlines()]
open(filename, "w").close() # empty logs
print('logs = ', logs)
>>> logs = []
host.json
:
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"default": "Debug"
}
}
}
然后我从post尝试了这个替代方案host.json
:
"logging": {
"fileLoggingMode": "debugOnly",
"logLevel": {
"default": "None",
"Host.Results": "Information",
"Function": "Information",
"Host.Aggregator": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false,
"maxTelemetryItemsPerSecond": 5
}
}
}
azure-pipeline-ontology_tagger.yaml
# ##########
# A build run against multiple Python targets
# ##########
resources:
- repo: self
variables:
tag: '$(Build.SourceBranchName)-$(Build.BuildNumber)'
imageName: '$(Build.Repository.Name)-ontology_tagger'
artifactFeed: grandproject/private-sources
repositoryUrl: private-sources
packageDirectory: workers/ontology_tagger
trigger:
batch: true
branches:
include:
- master
- development
- releases/*
paths:
include:
- "workers/ontology_tagger"
exclude:
- "workers"
- "*.md"
pr:
branches:
include:
- master
- development
- releases/*
paths:
include:
- "workers/ontology_tagger"
exclude:
- "workers"
- "*.md"
stages:
- stage: BuildWP
displayName: Build Workers python package
jobs:
- job: Build
displayName: Build Worker python image
pool:
name: EKS-grandproject-dev
steps:
- bash: env
- task: PipAuthenticate@0
displayName: Authenticate with artifact feed
inputs:
artifactFeeds: $(artifactFeed)
- task: TwineAuthenticate@1
displayName: Authenticate with artifact feed
inputs:
artifactFeed: $(artifactFeed)
- bash: echo "##vso[task.setvariable variable=POETRY_HTTP_BASIC_AZURE_PASSWORD;isOutput=true]$(echo $PIP_EXTRA_INDEX_URL | sed -r 's|https://(.+):(.+)@.*|\2|')"
name: "PIPAUTH"
- task: Bash@3
displayName: Test worker
inputs:
targetType: 'inline'
workingDirectory: '$(packageDirectory)'
script: |
docker build . --progress plain --pull --target test \
--build-arg POETRY_HTTP_BASIC_AZURE_PASSWORD=${PIPAUTH_POETRY_HTTP_BASIC_AZURE_PASSWORD} \
--build-arg ATLASSIAN_TOKEN=$(ATLASSIAN_TOKEN)
- task: Bash@3
displayName: Build and publish package
inputs:
targetType: 'inline'
workingDirectory: '$(packageDirectory)'
script: |
set -e
cp $(PYPIRC_PATH) ./
docker build . --target package --progress plain --build-arg REPO=$(repositoryUrl)
- task: Bash@3
displayName: Build docker image
inputs:
targetType: 'inline'
workingDirectory: '$(packageDirectory)'
script: |
docker build . --tag '$(imageName):$(tag)' --progress plain --pull --target production \
--build-arg POETRY_HTTP_BASIC_AZURE_PASSWORD=${PIPAUTH_POETRY_HTTP_BASIC_AZURE_PASSWORD} \
--label com.azure.dev.image.build.sourceversion=$(Build.SourceVersion) \
--label com.azure.dev.image.build.sourcebranchname=$(Build.SourceBranchName) \
--label com.azure.dev.image.build.buildnumber=$(Build.BuildNumber)
- task: ECRPushImage@1
displayName: Push image with 'latest' tag
condition: and(succeeded(),eq(variables['Build.SourceBranchName'], 'master'))
inputs:
awsCredentials: 'dev-azure-devops'
regionName: 'eu-central-1'
imageSource: 'imagename'
sourceImageName: $(imageName)
sourceImageTag: $(tag)
repositoryName: $(imageName)
pushTag: 'latest'
autoCreateRepository: true
- task: ECRPushImage@1
displayName: Push image with branch name tag
condition: and(succeeded(),ne(variables['Build.SourceBranchName'], 'merge'))
inputs:
awsCredentials: 'iotahoe-dev-azure-devops'
regionName: 'eu-central-1'
imageSource: 'imagename'
sourceImageName: $(imageName)
sourceImageTag: $(tag)
repositoryName: $(imageName)
pushTag: '$(Build.SourceBranchName)'
autoCreateRepository: true
- task: ECRPushImage@1
displayName: Push image with uniq tag
condition: and(succeeded(),ne(variables['Build.SourceBranchName'], 'merge'))
inputs:
awsCredentials: 'dev-azure-devops'
regionName: 'eu-central-1'
imageSource: 'imagename'
sourceImageName: $(imageName)
sourceImageTag: $(tag)
repositoryName: $(imageName)
pushTag: $(tag)
autoCreateRepository: true
outputVariable: 'ECR_PUSHED_IMAGE_NAME'
如果还有什么需要我提供的,请告诉我
我认为您在这里基本上混淆了一些东西:您提供的链接和下面的链接提供了有关设置Azure登录功能的指导。然而,您似乎在谈论登录Azure管道,这是一件完全不同的事情。因此,我想说清楚:
Azure管道运行构建和部署作业,这些作业将您可能在GitHub存储库中拥有的代码部署到Azure功能。管道在Azure管道代理中执行,这些代理可以是Microsoft代理,也可以是自托管代理。如果我们假设您正在使用Microsoft托管代理执行管道,则不应假设这些代理具有Azure函数可能具有的任何功能(也不应首先执行针对Azure函数的代码)。如果您想在管道中执行python代码,您应该首先查看托管代理预先安装了哪些python相关功能,并从中开始工作:https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml
如果要记录有关管道运行的信息,在手动排队管道时,应首先选中“启用系统诊断”选项。要自己实现更多日志记录,请检查:https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash
对于登录Azure函数,您可能希望从这里开始:https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring,但这与登录Azure管道是完全不同的主题
相关问题 更多 >
编程相关推荐