0

I have a python script using boto3 to create a instance on AWS and I'm using Jenkinsfile to automate it. In the Jenkinsfile I defined some parameters to put the information that we want. And I want that my python script capture those values in the value field.

Is there a module that allow me to get those values from Jenkinsfile or is there a way to call them?

Jenkinsfile:

    parameters {
    string(name: 'INSTANCETYPE', defaultValue: 't2.micro', description: 'e.g. t2.micro')
    string(name: 'PR', defaultValue: '', description: 'Project')
    string(name: 'OWNER', defaultValue: '', description: 'Owner for instance')
    string(name: 'OS', defaultValue: '', description: 'Operative System e.g REDHAT')       
}

test.py

ec2.create_tags(
Resources=[
    instances[0].id,
],
Tags=[
  {
    'Key': 'Instance',
    'Value': 'INSTANCETYPE'
  },
  {
    'Key': 'PR',
    'Value': 'PR'
  },
  {
    'Key': 'Owner_Instance',
    'Value': 'OWNER'
  },
  {
    'Key': 'Operative_System',
    'Value': 'OS'
  },
]

)

dahwild
  • 35
  • 1
  • 6
  • Parameters in Jenkins should be set as environment variables by Jenkins before Jenkins calls your script. Possible duplicate of https://stackoverflow.com/questions/39119698/how-to-use-jenkins-parameters-in-a-shell-script – William D. Irons Sep 23 '21 at 19:48
  • You would pass the parameter values as input arguments to your python script. Please add your shell step method for your pipeline's execution of the python script to the question so that we can assist further. – Matthew Schuchard Sep 23 '21 at 20:03

0 Answers0