1
image : mcr.microsoft.com/dotnet/core/sdk:3.1 

.deploy: &deploy
      before_script:
        - apt-get update -y
      script:
        - cd source/
        - pip install -r requirements.txt
        - python build_file.py > swagger.yml

I want to run the build_file.py file and write the output to swagger.yml. So to run the file I need to install python. How can I do that?

3
  • Seems you have a Debian-based system there, so do it like any package management there with apt. Alternatively, use an image that comes with Python already installed. Commented Jan 17, 2022 at 7:52
  • Thanks for the answer but can you please provide the script for that. It'll be really helpful Commented Jan 17, 2022 at 7:58
  • Can you specify what this script should do in a single sentence? For example, "how to calculate with Arabic numbers". You then type this into the search bar of your browser and look at the results. Commented Jan 17, 2022 at 8:00

1 Answer 1

1

You can use a different Docker image for each job, so you can split your deployment stage into multiple jobs. In one use the python:3 image for example to run pip and generate the swagger.yml, then define it as an artifact that will be used by the next jobs.

Example (untested!) snippet:

deploy-swagger:
  image: python:3
  stage: deploy
  script:
    - cd source/
    - pip install -r requirements.txt
    - python build_file.py > swagger.yml
  artifacts:
    paths:
      - source/swagger.yml

deploy-dotnet:
  image: mcr.microsoft.com/dotnet/core/sdk:3.1
  stage: deploy
  dependencies:
    - deploy-swagger
  script:
    - ls -l source/swagger.yml
    - ...

You could (probably should) also make the swagger generation be part of previous stage and set an expiration for the artifact. See this blog post for example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.