English 中文(简体)
从文本档案中获取内容,将其保存成一个可变的版本。
原标题:Get content from text file and save it into a variable - Azure YML

我有一只 t子,一米试图在变数中挽救所有内容,但我只想把内容的第一行带上变数。

greetings.txt

- hello: 123 
- hello: 456
- hello: 789 

azure-line.yml

variables:
- name: MY_TEXT_FILE
  value:  greetings.txt 
  readonly: true

# Save text file in this variable
- name: GREETINGS_CONTENT
  value:   

   steps:
    - task: Bash@3
      displayName:  Save text file content in a variable 
      inputs:
        targetType:  inline 
        script: |
          echo "##vso[task.setvariable variable=GREETINGS_CONTENT]$(cat $MY_TEXT_FILE)"

    - task: Bash@3
      displayName:  Another task 
      inputs:
        targetType: inline
        script: |
          # This is only printing the first line of the txt file
          # I want to save ALL the txt file content in the variable
          echo "My greetings are: $GREETINGS_CONTENT"

页 次 执行另一项任务:

Actual results:

- hello: 123

<>>预期成果:

- hello: 123 
- hello: 456
- hello: 789

我需要更新什么才能取得预期结果?

问题回答

在DevOps,multi-line factors有几处限制,请查看这个专题的用户语音票:。 建造和释放中的多线变量。

为了解决这一问题,我们可以将价值转换为64类。 然后在下一个任务中将变值编码。

variables:
- name: MY_TEXT_FILE
  value:  greetings.txt 
  readonly: true

# Save text file in this variable
- name: GREETINGS_CONTENT
  value:   

steps:
- task: Bash@3
  displayName:  Save text file content in a variable 
  inputs:
    targetType:  inline 
    script: |
      testcontent=$(cat $MY_TEXT_FILE)
      export test=$(echo "$testcontent"| base64 -w 0)
      echo "##vso[task.setvariable variable=GREETINGS_CONTENT]$test"

- task: Bash@3
  displayName:  Another task 
  inputs:
    targetType: inline
    script: |
      # This is only printing the first line of the txt file
      # I want to save ALL the txt file content in the variable
      export content=$(echo "$(GREETINGS_CONTENT)" | base64 -d -w 0)
      echo $content

“entergraph

请查到:https://stackoverflow.com/a 77845820/14996050“>similar张票/a>供您参考。





相关问题
Team foundation server in the cloud?

We have been using TFS on our own server for a while. We would like to move it in the cloud. Is there any good hosted service? Note: we would like to import all our source and projects

热门标签