title: How to use global credentials in python script invoked by jenkins pipeline
body: <p>I'm very new to working with jenkins, so far I was able to run simple pipeline with simple pip install, but I need to pass global credentials from Jenkins into python script test.py invoked by jenkinsfile.</p>
  <p><a href="https://i.stack.imgur.com/Ow7eV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ow7eV.png" alt="Credentials" /></a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>pipeline {
      options { timeout(time: 30, unit: 'MINUTES')
              buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30')) }
      agent { label 'ops_slave' }
      stages {
          stage('Environment  Build') {
              steps {
                  echo "Hello World!"
                  sh "echo Hello from the shell"
                  sh "hostname"
                  sh "uptime"
                  sh "python3 -m venv test_env"
                  sh "source ./test_env/bin/activate"
                  sh "pip3 install pandas psycopg2"
                  sh """echo the script is working"""
                  withCredentials([[
                      $class: 'UsernamePasswordMultiBinding',
                      credentialsId: 98,
                      usernameVariable: 'user',
                      passwordVariable: 'pw',
                  ]])
                  sh """python3 bartek-jenkins-testing/python/test.py"""
              }
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>I've seen implementation where you use argparse, but it's way above my level at this point, and I believe there is a way to reference it from python script or jenkins directly to pass to python script. I was googling for some time now, but I'm not sure questions I'm asking are correct.</p>
  <p>My python script should be able to get username and password from Jenkins global credentials ID98:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>print('Hello World this is python')
  import pandas as pd
  print(pd.__version__)
  import pyodbc
  import psycopg2
  # can pass environemtn variables
  
  connection = psycopg2.connect(
      host="saturn-dv",
      database="saturn_dv",
      port='8080',
      user='saturn_user_bartek_malysz',
      password='')
  connection.set_session(readonly=True)
  query = """
  SELECT table_name FROM information_schema.tables
  WHERE table_schema = 'public'
  ORDER BY table_schema,table_name;"""
  data = pd.read_sql(query, connection)
  print(data)</code></pre>
  </div>
  </div>
  </p>