小编Krz*_*tof的帖子

如何在带有变量组的 azure DevOps yaml 管道的变量中使用 IF ELSE?

除了变量组之外,我还尝试将 2 个值之一分配给变量,但找不到有关如何使用 IF ELSE 的参考。

基本上我需要将这个 jerkins 逻辑转换为 azure DevOps。

詹金斯

if (branch = 'master') { 
   env = 'a'
} else if (branch = 'dev'){
    env ='b'
}
Run Code Online (Sandbox Code Playgroud)

我从下一个中找到了 1 个参考,但是如果变量部分没有变量组,这个参考似乎有效。

/sf/answers/4027276851/

但是在我的管道中,我已经有一个用于秘密的变量组,所以我必须使用名称/值约定,并且该示例不适用于诸如expected a mappingorA mapping was not expected或 or 之类的错误Unexpected value 'env'

variables:
- group: my-global
- name: env
  value:
    ${{ if eq(variables['Build.SourceBranchName'], 'master') }}: 
      env: a
    ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}: 
      env: b

Run Code Online (Sandbox Code Playgroud)

或者

variables:
- group: my-global
- name: env
  value: …
Run Code Online (Sandbox Code Playgroud)

azure-devops azure-pipelines azure-pipelines-yaml

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

如何使用azure devops管道执行sql脚本

我有 SQL 脚本,我想使用 azure DevOps 管道执行

我找到了多个 SQL 任务,但找不到任何可以传递 sql server 、数据库名称和登录详细信息的所需任务。有可用的任务吗?

如果没有任何可用任务,唯一的执行方法是 powershell 脚本,有可用的示例脚本吗?

sql-server powershell azure-devops azure-pipelines

23
推荐指数
3
解决办法
4万
查看次数

如何打印 terraform 变量值?

我正在学习地形。我想在“计划”阶段打印变量的值。所以我找到了该怎么做。似乎我在这里做错了什么......

在变量.tf中:....

variable "VMCount" {
    description = "How many VMs do you want to start with (number)? default=1 max=5"
    type = number
}
Run Code Online (Sandbox Code Playgroud)

在 main.tf 中

output "VMCount" {
  value = "${var.VMCount > 2 && var.VMCount < 6 ? var.VMCount : 2}"
}
Run Code Online (Sandbox Code Playgroud)

之后我运行 terraform plan 并且条件似乎工作正常(它创建了正确数量的虚拟机)

但变量输出还没有到来。为什么?

$ terraform output
VMC = 56
Run Code Online (Sandbox Code Playgroud)

VMC 可能来自之前的一些尝试(我尝试了几件事)。

如何打印用户输入的值(变量)?

谢谢。

infrastructure terraform azure-devops azure-pipelines

21
推荐指数
2
解决办法
8万
查看次数

使用 GitHub Actions 在工作流程中创建 .env 文件

我最近创建了这篇文章,试图弄清楚如何在 GitHub 操作中引用 GitHub Secrets。我相信我已经解决并弄清楚了这个问题,并且我正在解决另一个问题。

下面是目前工作流程代码的示例,我需要帮助的问题是这Create and populate .Renviron file部分。

on: [push, pull_request]
name: CI-CD
jobs:
  CI-CD:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      # we keep a matrix for convenience, but we would typically just run on one
      # single OS and R version, aligned with the target deployment environment
      matrix:
        config:
          - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

    env:
      # Enable RStudio Package Manager to speed up package installation …
Run Code Online (Sandbox Code Playgroud)

r github shiny github-actions

20
推荐指数
2
解决办法
2万
查看次数

Github Actions 中的 If 或条件

我一直在尝试在 Github actions 中构建 CICD 管道,但我们无法在其中处理 if 和 or 条件。下面是我们的代码片段的示例,

    name: Build Non prod
    needs: [rules]    
    if: ${{ (needs.rules.outputs.branch_name != 'production') || (needs.rules.outputs.branch_name != 'staging') }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
Run Code Online (Sandbox Code Playgroud)

因此,此任务不应在分支中运行productionstaging但是当操作在staging分支中运行时,此作业也会与不适合staging环境的其他作业一起被触发。

有什么办法可以拥有ifor条件吗?

更新:

该条件将不起作用,更新后的条件将起作用。

if: ${{ (needs.rules.outputs.branch_name != 'production') && (needs.rules.outputs.branch_name != 'staging') }}
Run Code Online (Sandbox Code Playgroud)

github github-actions cicd

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

如何使用模板引用 Azure DevOps Pipelines 中另一个存储库中的脚本?

我正在尝试使用存储在 Azure DevOps 中另一个 Git 存储库中的模板,其中该模板引用了也包含在该存储库中的脚本。虽然我可以成功使用主管道中的模板,但它没有引用模板所需的脚本。

请问我有什么办法可以做到这一点吗?

HelloWorld 模板/脚本存储在 Azure DevOps Repo“HelloWorld”中名为“Templates”的子文件夹中。

HelloWorld.ps1 脚本与以下模板位于同一目录中。

param($Name)

Write-Host "Hello, $Name!"
Run Code Online (Sandbox Code Playgroud)

模板 #1 参考本地脚本

param($Name)

Write-Host "Hello, $Name!"
Run Code Online (Sandbox Code Playgroud)

模板#2

  parameters:
  - name: azureSubscription
    type: string
  - name: name
    type: string
  
  jobs:
  - job: HelloWorld
    displayName: Hello World
    variables:
      name: ${{ parameters.name }}
    steps:
    - task: AzurePowerShell@4
      name: HelloWorld
      displayName: Hello World
      inputs:
        azureSubscription: ${{ parameters.azureSubscription }}
        scriptType: filePath
        scriptPath: ./HelloWorld.ps1
        azurePowerShellVersion: latestVersion
        failOnStandardError: true
        scriptArguments:
          -Name "$(name)"
Run Code Online (Sandbox Code Playgroud)

azure azure-devops azure-pipelines

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

如何删除二头肌模板及其已部署的资源

如何删除或更新二头肌模板及其部署的所有资源?就像我们可以删除或更新cloudformation和terraform模板一样

az 部署命令没有更新选项,并且在使用 az 部署删除时它不会删除资源

azure azure-cli azure-devops azure-bicep

15
推荐指数
1
解决办法
9815
查看次数

如何修复“优化机会”

我正在使用 xcode 12。我编写了扩展 UI 视图,如下所示:

@IBInspectable
public var shadowRadius: CGFloat {
    get {
        return layer.shadowRadius
    }
    set {
        layer.shadowRadius = newValue
    }
}

@IBInspectable
public var shadowOpacity: Float {
    get {
        return layer.shadowOpacity
    }
    set {
         layer.shadowOpacity = newValue
    }
}

@IBInspectable
public var shadowOffset: CGSize {
    get {
        layer.shadowOffset
    }
    set {
         layer.shadowOffset = newValue
    }
}

@IBInspectable
public var shadowColor: UIColor {
    get {
        return UIColor(cgColor: layer.shadowColor ?? UIColor.clear.cgColor)
    }
    
    set {
        layer.shadowColor = newValue.cgColor
    }
}
Run Code Online (Sandbox Code Playgroud)

一切正常,但是当我调试视图时,我看到了一些像这样的紫色警告。 …

debugging xcode uiview swift

14
推荐指数
1
解决办法
5870
查看次数

Azure DevOps 管道中的条件阶段执行

我希望根据前一阶段中设置的变量的内容来执行 Azure DevOps 管道中的一个阶段。

这是我的管道:

stages:
  - stage: plan_dev
    jobs:
    - job: terraform_plan_dev
      steps:
      - bash: echo '##vso[task.setvariable variable=terraform_plan_exitcode;isOutput=true]2'
        name: terraform_plan

  - stage: apply_dev
    dependsOn: plan_dev
    condition: eq(stageDependencies.plan_dev.terraform_plan_dev.outputs['terraform_plan.terraform_plan_exitcode'], '2')
    jobs:
    - deployment: "apply_dev"
      ...
Run Code Online (Sandbox Code Playgroud)

apply_dev如果阶段plan_dev没有显示任何变化,我们的想法是跳过该阶段。背景是,我们在该阶段需要手动批准部署,plan_dev如果没有需要批准的更改,我们希望跳过该阶段。

不幸的是这似乎不起作用。无论变量是否terraform_plan_exitcode设置为期望值(2),都会apply_dev跳过该阶段。

对于语法,我遵循此处的文档

stageDependencies.StageName.JobName.outputs['StepName.VariableName']
Run Code Online (Sandbox Code Playgroud)

azure terraform azure-devops azure-pipelines

12
推荐指数
2
解决办法
2万
查看次数

如何在azure devops中将变量从一个管道传递到另一管道

我有两个管道(管道 A 和管道 B)配置为构建和发布,管道 A 触发管道 B 进行部署。

我在管道 A 上定义了变量,并需要在管道 B 上使用它们来进行部署。是否可以在这两个管道之间传递它们?

非常感谢任何线索。

azure-devops azure-pipelines

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