将Git Log存储在YAML管道中的某个变量中- Azure DevOps

qqrboqgw  于 2023-03-06  发布在  Git
关注(0)|答案(1)|浏览(206)
name: "Sample"

trigger:
- main

pool:
  vmImage: windows-latest

variables: 
- template: Pipeline/vars/global-pipeline.vars.yaml
- name: gitLog
  value: ''

steps:

- script: |
    $gitLog = git log
    echo $gitLog
  workingDirectory: $(Build.SourcesDirectory)
  displayName: 'Fetch Git Log and Store in a variable'

以上是我的Azure DevOps Yaml管道示例,我的目标是获取“Git Log”,存储在某个变量中,并将其传递给此管道中的其他操作。我声明了一个变量 gitLog,我想使用以下任务获取git命令 git log 的值并存储在git log中,但我遇到错误-
“$gitLog”未被识别为内部或外部命令

ubof19bj

ubof19bj1#

使用Ubuntu虚拟机

pool:
  vmImage: ubuntu-latest

variables: 
- name: gitLog
  value: ''

steps:
- script: |
    gitLog=$(git log)
    echo $gitLog
    echo "##vso[task.setvariable variable=gitLog]$(echo $gitLog)"
  workingDirectory: $(Build.SourcesDirectory)
  displayName: 'Fetch Git Log and Store in a variable'
- script: |
    echo "As pipeline variable gitLog: $(gitLog)"
    echo "As environment variable GITLOG: $GITLOG"

使用Windows虚拟机

pool:
  vmImage: windows-latest

variables: 
- name: gitLog
  value: ''

steps:
- powershell: |
    $gitLog=git log
    echo $gitLog
    echo "##vso[task.setvariable variable=gitLog]$(echo $gitLog)"
  workingDirectory: $(Build.SourcesDirectory)
  displayName: 'Fetch Git Log and Store in a variable'
- script: |
    echo "Pipeline variables gitLog: $(gitLog)"

**注意:**您需要使用task.setvariable来设置管道变量gitLog,它与bash变量$gitLog不同
演示运行

阅读文档了解更多详细信息

相关问题