带有变量的GitLab CI问题

时间:2018-10-08 14:36:37

标签: gitlab gitlab-ci

我正在尝试使用3个参数调用EXE,这些参数是在GitLab中定义的CI变量,但是最后一个变量参数未正确传递。

具体地说,我正在调用nuget.exe将程序包推送到运行baget的本地服务器。

我的.gitlab-ci.yml配置(仅相关部分):

NuGetDeploy:
  stage: deploy
  only:
    - tags
  tags:
    - csharp
  script:
    - cd $BUILD_PROJECT
    - mv *.nupkg "$NUGET_PKG_ID.nupkg"
    - nuget push "$NUGET_PKG_ID.nupkg" -ForceEnglishOutput -Verbosity detailed -NoSymbols -Source $NUGET_FEED_URL -ApiKey $NUGET_API_KEY -NonInteractive
    - cd ..
  artifacts:
    untracked: true
    expire_in: 4 weeks
  dependencies:
    - NuGetPack

NuGetDeploy作业中发生错误:

$ nuget push "$NUGET_PKG_ID.nupkg" -ForceEnglishOutput -Verbosity detailed -NoSymbols -Source $NUGET_FEED_URL -ApiKey $NUGET_API_KEY -NonInteractive
NuGet Version: 4.7.1.5393
Pushing Skiba.Testspace.NuGetTest.nupkg to 'http://baget.mycompany.org/v2/package'...
  PUT http://baget.skibapro.de/v2/package/
Please provide credentials for: http://baget.mycompany.org/v3/index.json
UserName: Password: An error was encountered when fetching 'PUT http://baget.mycompany.org/v2/package/'. The request will now be retried.
The HTTP request to 'PUT http://baget.mycompany.org/v2/package/' has timed out after 300000ms.

奇怪的是,当我交换Source和ApiKey参数

- nuget push "$NUGET_PKG_ID.nupkg" -ForceEnglishOutput -Verbosity detailed -NoSymbols -ApiKey $NUGET_API_KEY -Source $NUGET_FEED_URL -NonInteractive

然后发生此错误:

$ nuget push "$NUGET_PKG_ID.nupkg" -ForceEnglishOutput -Verbosity detailed -NoSymbols -ApiKey $NUGET_API_KEY -Source $NUGET_FEED_URL -NonInteractive
NuGet Version: 4.7.1.5393
Source parameter was not specified.
System.ArgumentException: Source parameter was not specified.
   at NuGet.Commands.CommandRunnerUtility.ResolveSource(IPackageSourceProvider sourceProvider, String source)
   at NuGet.Commands.PushRunner.<Run>d__0.MoveNext()

这意味着我的CI配置或GitLab的解释有问题。 NUGET_FEED_URL设置为http://baget.mycompany.org/v3/index.json,而NUGET_API_KEY设置为不带空格的字母数字字符串。 NUGET_API_KEY在GitLab的CI配置用户界面中被标记为受保护。

nuget可执行文件已手动安装并添加到系统的全局PATH env var中。运行程序位于Windows Server 2016主机上,并使用PowerShell执行程序。在PowerShell中手动执行push命令,将变量替换为其配置的值即可在该系统上正常运行。无需任何身份验证即可从跑步者的主机访问/v3/index.json

我尝试了-Param $UNQUOTED-Param "$QUOTED"的变体,也没有运气。猜猜这里可能有什么问题吗?

1 个答案:

答案 0 :(得分:0)

仅供参考:我忘记将master分支设置为protected,因此NUGET_API_KEY变量一直为空。 m(

相关问题