简体   繁体   English

在gitlab-ci中运行python脚本时使用正确目录的问题

[英]Issues with using proper directory when running python script in gitlab-ci

I have a python script that I am trying to run as part of gitlab pages deployment of a jekyll site. 我有一个python脚本,正在尝试将其作为jekyll网站的gitlab页面部署的一部分运行。 My site has blog posts that have various tags, and the python script generates the .md files for the tag pages. 我的网站上的博客文章带有各种标签,并且python脚本为标签页生成.md文件。 The script works perfectly fine when I just manually run it in an IDE, however I want it to be part of the gitlab ci deployment process 当我在IDE中手动运行该脚本时,该脚本运行良好,但是我希望它成为gitlab ci部署过程的一部分

here is what my gitlab-ci.yml setup looks like: 这是我的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

however, it doesn't actually create the files that it's supposed to create, here is the output from the job "run": 但是,它实际上并没有创建它应该创建的文件,这是作业“运行”的输出:

...
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

the script reads out "tags generated, count ___" once it's executed, so it is running, however the files that it's supposed to create aren't being created/uploaded into the right directory. 该脚本在执行后便会读出“生成的标签,计数___”,因此该脚本正在运行,但是并没有创建本应创建的文件/将其上传到正确的目录中。 there is a /tag directory in the root project folder, that is where they are supposed to go. 在根项目文件夹中有一个/ tag目录,应该在该目录中。

I realize that the issue must have something to do with the public folder, however when I don't have 我意识到问题一定与公用文件夹有关,但是当我没有

artifacts:
    paths:
    - public

it still doesn't create the files in the /tag directory, so it doesn't work whether I have -public or not, and I don't know what the problem is. 它仍然不会在/ tag目录中创建文件,因此无论我是否具有-public都行不通,而且我也不知道问题出在哪里。

I FIGURED IT OUT! 我想到了!

the "build" for the project isn't made in the repo, gitlab clones the repo into another place, so I had to change the artifact path for the python job so that it's in the cloned "build" location, like so: 该项目的“构建”不是在存储库中进行的,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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM