标签: azure-devops-pipelines

具有 Terraform 的 Azure DevOps Pipelines 在 arm_xxx 参数上失败

我们在 Azure-Devops 中有多个管道执行 Terraform init-plan-apply。到目前为止,工作正常。\n但是突然间,我们在 Init 阶段遇到了这些错误。

\n
Initializing the backend...\n\xe2\x95\xb7\n\xe2\x94\x82 Error: Invalid backend configuration argument\n\xe2\x94\x82 \n\xe2\x94\x82 The backend configuration argument "arm_subscription_id" given on the command line is not expected for the selected backend type.\n\xe2\x95\xb5 Error: Invalid backend configuration argument\n\xe2\x94\x82 \n\xe2\x94\x82 The backend configuration argument "arm_tenant_id" .....\n\xe2\x94\x82 The backend configuration argument "arm_client_id" .....\n\xe2\x94\x82 The backend configuration argument "arm_client_secret" ....\n
Run Code Online (Sandbox Code Playgroud)\n

在hasicorp网站上我发现了一个关于这个https://www.terraform.io/upgrade-guides/0-15.html的评论。\n但是init命令的生成完全是由DevOps完成的,没有地方我可以将arm_client_id更改为client_id(以及其他)。

\n

任何人都见过这种行为并能够解决它。

\n

terraform-provider-azure azure-devops-pipelines

6
推荐指数
1
解决办法
1699
查看次数

在 Azure DevOps Pipeline 模板中使用变量

我们有一组 Azure DevOps 管道模板,我们可以在多个存储库中重复使用这些模板。因此,我们希望有一个包含所有模板变量的文件。

回购结构看起来像这样

template repo
  ??? template-1.yml
  ??? template-2.yml
  ??? variables.yml

project repo
  ??? ...
  ??? azure-pipelines.yml
Run Code Online (Sandbox Code Playgroud)

variables.yml这个样子的

...
variables:
  foo: bar
Run Code Online (Sandbox Code Playgroud)

template-1.yml我们导入这里variables.yml描述的

variables:
- template: variables.yml
Run Code Online (Sandbox Code Playgroud)

azure-pipelines.yml我们使用这样的模板

resources:
  repositories:
    - repository: build-scripts
      type: git
      name: project-name/build-scripts

steps:
  ...
  - template: template-1.yml@build-scripts
    
Run Code Online (Sandbox Code Playgroud)

当我们现在尝试运行管道时,我们收到以下错误消息:

template-1.yml@build-scripts (Line: 10, Col: 1): Unexpected value 'variables'
Run Code Online (Sandbox Code Playgroud)

yaml azure azure-devops azure-devops-pipelines

5
推荐指数
2
解决办法
4640
查看次数

如何使用“.Net FrameWork 4.7”项目在 Azure DevOps Pipeline 上创建 Coverlet 覆盖率报告?

我目前正在尝试使用 Azure DevOps 上的管道创建 Coverlet 覆盖率报告。但是,由于我的项目是“.Net FrameWork 4.7”项目,因此我无法像“.Net Core”项目一样使用“DotNetCoreCLI@2”任务创建覆盖率报告。

这是我的管道代码:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  buildPlatform: 'Any CPU'
  buildConfiguration: 'release'
  Tests.Filter: '**\UnitTestProject1.dll'
  Tests.Filter.Criteria: 'TestCategory!=Medium&TestCategory!=Large'
  Tests.Filter.SettingsFile:

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '**/*.sln'

- task: DotNetCoreCLI@2
  displayName: Test   
  inputs:
    command: 'test'
    projects: |
            $(Tests.Filter)
            !**\obj\**
    publishTestResults: true
    arguments: -c $(BuildConfiguration) --collect:"XPlat Code Coverage"
    
- task: DotNetCoreCLI@2
  inputs:
    command: custom
    custom: tool
    arguments: install --tool-path . dotnet-reportgenerator-globaltool
  displayName: Install ReportGenerator tool

- script: reportgenerator -reports:$(Agent.TempDirectory)/**/*.coverage -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura" …
Run Code Online (Sandbox Code Playgroud)

.net frameworks code-coverage cobertura azure-devops-pipelines

5
推荐指数
1
解决办法
1302
查看次数

Azure Pipelines:“错误 NETSDK1004:未找到资产文件 '...\project.assets.json'。” 在使用 Cache@2 任务缓存 Nuget 包时在管道中

我有一个 .net core 3.1 解决方案,其中包含多个 Web 和类库项目。所有包都使用文件中的<PackageReference>格式.csproj

我正在使用 Azure DevOps Pipelines 构建解决方案,我想通过缓存 Nuget 包而不是在每次运行时从 nuget.org 恢复它们来减少我的构建时间。

按照文档和博客文章的一些指导,我已经:

  1. 将此nuget.config文件添加到我的解决方案中,以便始终从 nuget.org 恢复包:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
      </packageSources>
    </configuration>
    
    Run Code Online (Sandbox Code Playgroud)
  2. Directory.Build.props在我的解决方案中添加了一个文件,以便为每个项目packages.lock.json在构建时生成一个。

    <Project>
      <PropertyGroup>
        <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
        <DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
      </PropertyGroup>
    </Project>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将生成的packages.lock.json文件添加到 git。

  4. Cache@2任务集成到我的azure-pipeline.yml文件中,如下所示:

    trigger:
    - master
    - users/*
    
    pool:
      vmImage: 'windows-latest'
    
    variables:
      buildConfiguration: 'Debug'
      NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages
    
    steps:
    - task: Cache@2
      displayName: Cache nuget packages …
    Run Code Online (Sandbox Code Playgroud)

.net nuget .net-core azure-devops azure-devops-pipelines

5
推荐指数
1
解决办法
1928
查看次数

单击拉取请求中的完成按钮后,有没有办法在 Azure DevOps 中获取拉取请求 ID

我在创建 PR 后执行管道流,并且在单击完成按钮后需要获取拉取请求 ID。

我使用$(System.PullRequest.PullRequestId)来获取值,但它始终是一个空值,并给出错误输出“ System.PullRequest.PullRequestId:找不到命令

创建一个简单的经典管道,如下所示,需要在Branch Policies -> Status Check中调用它。 在此输入图像描述

注意:使用相同的变量$(System.PullRequest.PullRequestId)我可以在完成之前获取 ID,即当 PR 处于活动状态时。

azure-devops azure-devops-rest-api azure-devops-pipelines

5
推荐指数
1
解决办法
7972
查看次数

是否可以为管道模板中的阶段设置基于 System.PullRequest.TargetBranch 的条件?

我有一个解决方案,其中 git 分支与环境直接相关(必须是这样,所以请不要讨论这是好还是坏,我知道这不是最佳实践)。

我们可以选择对环境运行验证部署(包括自动测试),而无需实际将解决方案部署到环境中。因此,我想设置一个管道,每当向该环境的分支打开拉取请求时,就为该环境运行此验证。此外,我对大部分管道使用了模板。主存储库中的实际管道只是一个指向另一个存储库中的模板管道的微小解决方案。该模板又针对每个各自的环境具有阶段。

我在主管道中成功添加了一个标识当前分支的解决方案,对于拉取请求,该解决方案应该是目标分支:

variables:
  - name: currentBranch
    ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
      value: $(System.PullRequest.TargetBranch)
    ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
      value: $(Build.SourceBranch)
Run Code Online (Sandbox Code Playgroud)

我想currentBranch通过参数将此变量发送到模板,因为我的模板管道根据分支有不同的阶段。我的解决方案是使用这样的管道:

extends:
  template: <template-reference>
  parameters:
    branch: $(currentBranch)
Run Code Online (Sandbox Code Playgroud)

...然后对于我的管道中的一个阶段执行以下操作:

- stage: TestAndDeployBranchName
    condition: eq('${{ parameters.branch }}', 'refs/heads/branchName')
    jobs:
      - job1... etc.
Run Code Online (Sandbox Code Playgroud)

基本上,如果当前分支是“branchName”,或者(对于拉取请求)当目标分支是“branchName”(来自发送到模板的“branch”参数)时,该阶段应该运行。

但是,我在这里看到不适System.PullRequest.TargetBranch用于模板,并且进一步看到当模板展开时,参数不适用于模板(变量为空)。因此,我的管道无法按预期工作(条件在应有的时候没有触发,即当分支名称匹配时)。

有什么方法可以System.PullRequest.TargetBranch在模板内的条件中使用,或者我应该寻找其他解决方案吗?

azure-devops azure-pipelines azure-pipelines-yaml azure-devops-pipelines

5
推荐指数
1
解决办法
8777
查看次数

Azure Devops YML 条件阶段模板

视觉工作室 2019 16.8.5

我想使用阶段模板。有些阶段,我想根据条件而定。但是,当我在 YML 文件中尝试此操作时,它会生成错误。以下是 azure-pipelines.yml 文件中的两次尝试:

stages:
- template: 'build.yml'

- template: 'deploy.yml'

- template: 'test.yml'

- ${{ if eq('true', 'true') }}:
  - template: 'optional.yml'
Run Code Online (Sandbox Code Playgroud)

结果是:

Severity    Code    Description Project File    Line    Suppression State
Error       Property ${{ if eq('true', 'true') }} is not allowed.       azure-pipelines.yml 8   
Run Code Online (Sandbox Code Playgroud)

和这个:

stages:
- template: 'build.yml'

- template: 'deploy.yml'

- template: 'test.yml'

- template: 'optional.yml'
  condition: eq('true', 'true')
Run Code Online (Sandbox Code Playgroud)

结果是:

Severity    Code    Description Project File    Line    Suppression State
Error       Property template is not allowed. …
Run Code Online (Sandbox Code Playgroud)

azure-devops azure-devops-pipelines

5
推荐指数
1
解决办法
1万
查看次数

Azure Devops Pipeline - 在构建上下文中找不到文件

在 Azure DevOps Pipeline 中出现错误:

Step 7/17 : COPY ["demo6/demo6.csproj", "demo6/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6.csproj: file does not exist

Run Code Online (Sandbox Code Playgroud)

NOTES-在诊断模式下运行管道并且 .sln 文件存在

##[debug]cwd=/home/vsts/work/1/s
##[debug]  /home/vsts/work/1/s/demo6.sln (file)
##[debug]  /home/vsts/work/1/s/demo6/demo6.csproj (file)
Run Code Online (Sandbox Code Playgroud)

我有一个多项目的 Asp.Net Core 解决方案,文件夹结构和项目如下:

demo6
 |--demo6/demo6.csproj
 |--demo6.api/demo6.api.csproj
Run Code Online (Sandbox Code Playgroud)

该应用程序是 demo6,它引用了 demo6.api,它是一个类库。

这是在 GitHub 中的存储库 demo6。我修改了自动生成的 Dockerfile 以添加额外的 demo6/ 以查看是否有效,但没有。

感谢任何帮助。

Dockerfile 如下:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["demo6/demo6.csproj", "demo6/"]
RUN …
Run Code Online (Sandbox Code Playgroud)

docker azure-devops azure-devops-pipelines

5
推荐指数
1
解决办法
1138
查看次数

##[错误]在池代理中找不到满足指定要求的代理:maven,Agent.Version -gtVersion 2.163.1

我正在尝试在 Azure DevOps 服务上构建和发布管道,就像我使用在 Azure 托管的 linuxVM 上运行的自托管 Linux 代理一样。

早些时候,相同的管道在 Microsoft 托管代理上运行时没有出现错误。

现在我正在##[error]No agent found in pool ProjectAgent which satisfies the specified demands: maven, Agent.Version -gtVersion 2.163.1

我已经在自托管Linux代理上安装了Java a和maven

:/home/-agent/_work/2/s/kubernetes # echo $JAVA_HOME
/usr/lib64/jvm/java
:/home/l-agent/_work/2/s/kubernetes # echo $M2_HOME
/opt/apache-maven-3.6.3
:/home/heisoul-agent/_work/2/s/kubernetes #
Run Code Online (Sandbox Code Playgroud)

即使在代理能力中也反映了

在此输入图像描述

管道Yml

# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/java

resources:
- repo: self

trigger:
  batch: true
  branches: …
Run Code Online (Sandbox Code Playgroud)

maven-3 maven azure-devops azure-pipelines azure-devops-pipelines

5
推荐指数
1
解决办法
1万
查看次数

未找到与 **/test-*.xml 匹配的测试结果文件 - Azure DevOps

我正在尝试在天蓝色中发布测试结果,但我无法做到这一点。这是我使用 azure 的第二天,所以我可能会错过一些东西。

我的管道代码是

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/test-*.xml'
Run Code Online (Sandbox Code Playgroud)

karma.conf.js

junitReporter: {
             outputDir: '.',
             outputFile:'test-report.xml'
         },
Run Code Online (Sandbox Code Playgroud)

而且我用的是最新的ubuntu。但当我运行管道时总是会出现此错误

##[warning]No test result files matching **/test-*.xml were found.
Run Code Online (Sandbox Code Playgroud)

我尝试了小写大写,但没有任何效果,我不知道我做错了什么。我将感谢任何提示。

junit azure azure-devops angular azure-devops-pipelines

5
推荐指数
1
解决办法
7386
查看次数