【问题标题】:assign variable by bash script during variable declaration time在变量声明期间通过 bash 脚本分配变量
【发布时间】:2020-08-14 14:11:01
【问题描述】:

对于我的 azure-pipeline.yml 文件,我想通过 bash 脚本分配变量以从 repoName 中获取斜杠后的名称作为我的 imageName

variables:
  vmImageName: 'ubuntu-18.04'
  repoName: $(Build.Repository.Name)
  imageName: ${repoName##*/}

repoName 是 top/cci 我预计 imageName 的打印结果是 cci。但结果是 ${top/cci##*/}

如何在变量赋值过程中使用 bash 脚本来获取斜线后面的字符串?

【问题讨论】:

  • 对不起,我不明白。你能说出你想在imageName中拥有什么价值吗?

标签: bash variables azure-devops yaml azure-pipelines


【解决方案1】:

也许你可以试试这种格式:

pool:
  vmImage: 'ubuntu-latest'

variables:
  vmImageName: 'ubuntu-18.04'
  repoName: $(Build.Repository.Name)
  imageName: $(basename $(repoName))

steps:

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      echo ImageName = $(imageName)

- task: CmdLine@2
  inputs:
    script: |
      echo ImageName = $(imageName)

imageName: $(basename $(repoName)) 似乎对我很有效。

variables:
  vmImageName: 'ubuntu-18.04'
  repoName: $(Build.Repository.Name)
  imageName: $(basename $(repoName))

结果:

如果这不是您要找的,也许您要找的是Set variables in scripts...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 2014-07-12
    相关资源
    最近更新 更多