Home > OS >  How to read the content of CI CD Variable of type File into my docker container run on pipeline
How to read the content of CI CD Variable of type File into my docker container run on pipeline

Time:01-27

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"

CodePudding user response:

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"

CodePudding user response:

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()

  •  Tags:  
  • Related