运行power shell scrip
curl -X POST --data-urlencode 'payload={"channel": "#personal", "username": "Jenkins", "text": "Building $env:BUILD_NUMBER", "icon_emoji": ":computer:"}' https://xxxxxx.slack.com/services/hooks/incoming-webhook?token=aseaUO
或
curl -X POST --data-urlencode 'payload={"channel": "#personal-notification", "username": "Jenkins", "text": "Building ${BUILD_NUMBER}", "icon_emoji": ":computer:"}' https://xxxxxx.slack.com/services/hooks/incoming-webhook?token=aseaUO
{BUILD_NUMBER}未被curl有效负载中的实际内部版本号替换
- 编辑 我注意到我的sh脚本正在调用git \ bin \ sh.exe。这是一个问题吗?
尝试下面的评论之一 curl -X POST --data-urlencode $('payload = {0}“channel”:“#individual”,“username”:“Jenkins”,“text”:“Building {1}”,“icon_emoji”:“ :电脑:“{2}” - f“{”,$ env:rohan)“}”https://xxxxxx.slack.com/services/hooks/incoming-webhook?token=aseaUO我知道了
直接尝试在PS终端上运行脚本我得
答案 0 :(得分:0)
问题在于整个表达式都包含在单引号中,因此PowerShell不会评估您的$env:BUILD_NUMBER
表达式。
使用字符串格式表达式。注意,您还必须使用格式化来保持{}字符不在基本表达式之外,以避免运行时错误。
curl -X POST --data-urlencode $('payload={0}"channel": "#personal", "username": "Jenkins", "text": "Building {1}", "icon_emoji": ":computer:"{2}' -f "{", $env:BUILD_NUMBER) ,"}") https://xxxxxx.slack.com/services/hooks/incoming-webhook?token=aseaUO
答案 1 :(得分:0)
你的代码中的问题很少,首先是引号(ps中的变量未在引用中扩展)第二个(愚蠢)参数...如果没有工作则尝试使用此更改Build_Number为$ {BUILD_NUMBER}
$param = @()
$param = "-X POST"
$param += "--data-urlencode 'payload={""channel"": ""#personal"", ""username"": ""Jenkins"", ""text"": ""Building ${env:BUILD_NUMBER}", ""icon_emoji"": "":computer:""}'"
$param += "https://xxxxxx.slack.com/services/hooks/incoming-webhook?token=aseaUO"
$curl $param
或者
$param = ''
$param = "-X POST"
$param += "--data-urlencode 'payload={""channel"": ""#personal"", ""username"": ""Jenkins"", ""text"": ""Building ${env:BUILD_NUMBER}", ""icon_emoji"": "":computer:""}'"
$param += "https://xxxxxx.slack.com/services/hooks/incoming-webhook?token=aseaUO"
$curl $param