我正在尝试使用gitlab api获取gitlab项目信息。下面的powershell脚本在powershell ise中工作得很好
$projects = Invoke-WebRequest https://gitlab.mycompany.com/api/v4/projects/namespace%2fproject
但是在jenkins powershell插件中使用相同脚本时,我总是会收到错误404 Not found。我不知道它是否与url编码或powershell脚本编码有关。
我尝试在jenkins命令下面使用和不使用编码
powershell (script:'''
$project = Invoke-WebRequest
https://gitlab.mycompany.com/api/v4/projects/namespace%2fproject
echo $project
''', encoding: 'UTF-8', returnStdout: true)
任何帮助将不胜感激
答案 0 :(得分:0)
这可能是因为您的项目不是公开的或需要身份验证。转到您的帐户设置,然后访问访问令牌。生成一个新令牌,然后将其添加到您的请求标头中:
$gitUrl = "https://gitlab.mycompany.com/api/v4/projects/namespace%2fproject"
$head = @{'PRIVATE-TOKEN'= 'YourTokenHere'; 'Content-Type'='application/json'}
Invoke-WebRequest -Uri $gitUrl -headers $head
还要检查Invoke-RestMethod,它将响应解析为psobject(有时非常方便)