1

我有一个 python 脚本,我试图将它作为 jekyll 站点的 gitlab 页面部署的一部分运行。我的网站有带有各种标签的博客文章,python 脚本会为标签页面生成 .md 文件。当我在 IDE 中手动运行该脚本时,它工作得非常好,但是我希望它成为 gitlab ci 部署过程的一部分

这是我的 gitlab-ci.yml 设置的样子:

run:
  image: python:latest
  script:
  - python tag_generator.py
  artifacts:
    paths:
    - public
  only:
  - master

pages:
  image: ruby:2.3
  stage: deploy
  script:
    - bundle install
    - bundle exec jekyll build -d public
  artifacts:
    paths:
    - public
  only:
  - master

但是,它实际上并没有创建它应该创建的文件,这是作业“运行”的输出:

...
Cloning repository...
Cloning into '/builds/username/projectname'...
Checking out 4c8a47fe as master...
Skipping Git submodules setup
$ python tag_generator.py
Tags generated, count 23
Uploading artifacts...
WARNING: public: no matching files                 
ERROR: No files to upload                          
Job succeeded

该脚本在执行后会读出“生成的标签,计数___”,因此它正在运行,但是它应该创建的文件没有被创建/上传到正确的目录中。在根项目文件夹中有一个 /tag 目录,这是他们应该去的地方。

我意识到这个问题一定与公用文件夹有关,但是当我没有

artifacts:
    paths:
    - public

它仍然没有在 /tag 目录中创建文件,所以无论我有没有 -public 都不起作用,我不知道问题是什么。

4

1 回答 1

2

我想到了!

项目的“构建”不是在仓库中进行的,gitlab 将仓库克隆到另一个地方,所以我不得不更改 python 作业的工件路径,使其位于克隆的“构建”位置,如下所示:

run:
  image: python:latest
  stage: test
  before_script:
  - python -V               # Print out python version for debugging
  - pip install virtualenv
  script:
  - python tag_generator.py
  artifacts:
    paths:
    - /builds/username/projectname/tag
  only:
  - master
于 2019-01-30T15:29:38.697 回答