2

Recently I created a project and dockerize it. in order to write a .gitlab-ci.yml, I want to prepare a test stage to test my program.

in the middle of my python code, I ask from the user a username and password, but because in the gitlab-ci, everything should be executed automatically, I want to send username and password inside my gitlab-ci instead of reading from the input. how can I send a username and password which is a static phrase to my python code inside of my gitlab-ci?

Please pay attention that I don't want to use sys.args in my python code, because in real execution I want to read it from user really, but just in gitlab-ci, I want to send a specific username and password to that program so it can execute automatically.

Saeed
  • 159
  • 3
  • 13
  • Actually I used pass phrase to read username and password. Now after running my script, I want to send username and password automatically from gilab-ci. – Saeed Nov 28 '19 at 13:12

1 Answers1

2

You can use environment variables in GitLab to send username and password to your script:

https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables

These variables will then be available to your program in your gitlab-ci.yml file. How you access the variables depend on which shell you are using (cmd, powershell, sh, bash):

https://docs.gitlab.com/runner/shells/#overview

You can use it in some way like this:

myjob:
  stage: test
  script:
    - python myscript.py --username $username --password $password

Exactly how you get the username and password into your program is up to you. If you don't want to use command line arguments, you might be able to create a little helper script that sends in the username and password through stdin. Another alternative is to add command line arguments to make it easy to test your program.

MrBerta
  • 2,457
  • 12
  • 24