如何在Gitlab页面中将PowerShell与Gitlab CI一起使用?

时间:2017-06-02 01:03:17

标签: powershell continuous-integration gitlab gitlab-ci gitlab-pages

如何在用于部署到gitlab页面的.gitlab-ci.yml文件中使用带有Gitlab CI的PowerShell命令/脚本?

我正在尝试从build.ps1执行.gitlab-ci.yml文件,但当它到达build.ps1行时,会出错 / bin / bash:第5行:.build.ps1:找不到命令

我正在尝试使用PowerShell脚本转换我的仓库中的文件,并使用.gitlab-ci.yml将转换后的文件部署到gitlab页面

这是我的代码:

.gitlab.yml

pages:
  stage: deploy
  script:
  - mkdir .public
  - .\build.ps1
  - cp -r * .public
  - mv .public public
  artifacts:
    paths:
    - public
  only:
  - master

3 个答案:

答案 0 :(得分:5)

我已经能够找到解决自己问题的方法。

<强>解决方案

要使用Gitlab CI从 gitlab.com 上的import ctypes from ctypes import wintypes kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) kernel32.TerminateProcess.argtypes = (wintypes.HANDLE, wintypes.UINT) if __name__ == '__main__': import subprocess p = subprocess.Popen('notepad') if not kernel32.TerminateProcess(int(p._handle), 1): raise ctypes.WinError(ctypes.get_last_error()) 文件运行PowerShell命令/脚本,您需要确保.gitlab-ci.yml的内容文件如下所示。

注意:下面的.gitlab-ci.yml无需在您自己的计算机上安装Gitlab Runner,并且已经在http://gitlab.com网站上进行了测试。

.gitlab-ci.yml

答案 1 :(得分:1)

docker 镜像 philippheuer/docker-gitlab-powershell 已过时。 Github上的源码也被删除了。

我在我的gitlab-ci.yml中使用以下图片mcr.microsoft.com/powershell:latest更多可用信息here

scriptjob:
  stage: script
  image: 
    name: "mcr.microsoft.com/powershell:latest"
  script:
    - pwsh ./myscript.ps1

答案 2 :(得分:0)

对于任何无法通过powershell文件在gitlab CI / CD中启动grunt的人,请将此行添加到文件顶部:

$env:path += ";" + (Get-Item "Env:AppData").Value + "\npm"