windows batch: echo a multi-line variable with special characters (JiraRelease Notes from jenkins)

独自空忆成欢 提交于 2019-12-11 12:27:17

问题


I am using the JiraPlugin in Jenkins to produe a ReleaseNotes and my build job in Jenkins uses batch files.

In the executed batch file, when I just issue a set, I can see that the varibale exists with the Jira Release notes. But it is multi-line and starts with a # character.

my goal is to do a echo %RELEASE_NOTES_JENKINS% > ReleaseNotes.txt

but that never works. I tried using !! instead of %% around the variable but that also does not work. I get ECHO is off. when I try to echo the variable. Again, set does show it with the correct content:

RELEASE_NOTES_JENKINS=# New Feature
 - [XXXX-3525] Blahblahblah
 - [XXXX-3268] Blahblahblah
 - [XXXX-3119] Blahblahblah
# UNKNOWN
 - [XXXX-3545] [security] Blahblahblah
...

Jenkins runs on a Windows 7 Server. This is specific to windows Batch (cmd.exe) since simply piping the variable to a file works when the Jenkins runs on a Linux environment.

Any idea on how to make this work?


回答1:


Try

SET RELEASE_NOTES_JENKINS > ReleaseNotes.txt

instead of echo.




回答2:


Delayed expansion should work:

setlocal enableDelayedExpansion
echo !RELEASE_NOTES_JENKINS!>releasenotes.txt


来源:https://stackoverflow.com/questions/31717777/windows-batch-echo-a-multi-line-variable-with-special-characters-jirarelease-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!