skip to Main Content

I have gitlab variable stored in a file format

When I tried to access the file using my python code

like

variable Key :  KEY_FILE value: 'hsdasds' 

in my python code pack.py

with open($KEY_FILE) as f:
    f.read()

I get File not found error but its showing the file path when I did

before_script -echo ' $KEY_FILE'

My query is how can I read the content(I will read it in docker container as my python code will run in a docker container) of the file define in variable ..

docker run --rm -u $(id -u):$(id -g) -v "$PWD":/mnt python 'executors/pack.py' "$KEY_FILE"

2

Answers


  1. Chosen as BEST ANSWER

    I have resolved it by below ways

    1. First in gitlab-,ci.yml

      cp ${CI_PROJECT_DIR}/KEY_FILE /tmp/gitkey
      

    2.in Dockerfile

        ADD /tmp/gitkey
    
    1. Now in code

      with open("/tmp/gitkey") as f:
        f.read()
      

  2. Try to firstly copy the file to your current working directory

    cp $KEY_FILE .
    

    And then run

    docker run --rm -u $(id -u):$(id -g) -v "$PWD":/mnt python 'executors/pack.py' "/mnt/KEY_FILE"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search