2

Note: Never used jenkins before

I have a python script that takes in 3 arguments to run. Via a terminal you would use it like this:

python script.py arg1 arg2 arg3

I want to create a new jenkins job which basically utilizes this script and runs it after the 3 arguments have been provided. However I cannot find any examples which run such a job. The script is placed in a github repo so its path looks like this: https://github.com/username/repo/folder/script.py. This is what I did: 1. I went ahead and created a new job New Item --> Freestyle Project. 2. Under GitBucket --> Githubproject I added the path : https://github.com/username/repo/ 3. I then clicked on This build is parameterized and added 3 choice parameters which the possible options. 4. Then under build I selected execute shell and gave the command python script.py $param1 $param2 $param3

My question is that , in step 2, should I be giving the path to the script as https://github.com/username/repo/folder/script.py or is it right the way I have it now.

Any suggestions / links to tutorials will be helpful

2 Answers 2

1

If all you need is just a particular file - you can use only shell script enter image description here

#!/bin/bash

wget -q -O sample.py https://raw.githubusercontent.com/Alexhha/hello-world/master/python/sample.py
/usr/bin/python sample.py ${ARG1} ${ARG2} ${ARG3}

sample.py it's just a simple script

import sys

print 'Sample output: %s, %s, %s' % (str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3]))

Run sample build

enter image description here

You will get something like the following

enter image description here

the script is in a private repo

If you're cloning inside a script and need to avoid the prompts, you can add the token to the clone URL:

git clone https://<token>@github.com/owner/repo.git

or

git clone https://<token>:[email protected]/owner/repo.git

Note: Tokens should be treated as passwords. Putting the token in the clone URL will result in Git writing it to the .git/config file in plain text. Unfortunately, this happens for HTTP passwords, too.

1
  • the script is in a private repo. So if I get a raw file the URL has a suffix like https://raw.githubusercontent.com/company/repo/master/folder/script.py?token=AFdeHVdU0DxCT7zuCaQOl3Ed1dVWjtSks5W30NdwA%3D%3D. Will this token keep changing?
    – Beginner
    Mar 1, 2016 at 21:29
0

Sounds like you all you need to do is add the command in the exec shell dialog. The other settings sound right to me. What's in the console output of your Jenkins Job?

If you added the git repo location and the system has proper access to that repo, or if you setup credentials in the Jenkins job, try setting up an execute shell command by adding the full path to Python and the local path to script.

Our Jenkins installation executes from a local workspace container for each job.

Execute Shell:

/usr/bin/python ./folder/script.py $param1 $param2 $param3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .