How to get Jenkins to execute a script that it pulled from Git

githubJenkins

I am using Jenkins to trigger and manage a series of import jobs. I want to put my import script in Github, and when Jenkins builds the job, it should (a) pull that version controlled script out of Github and (b) run the script.

The problem that I am running into is that I don't know how to reference the name of the script to run within the job. I'm assuming that source code is pulled into the workspace directory. Is that assumption correct? (If only there was documentation!)

Here's what I've done so far:

  1. Installed Jenkins (obviously) on my Windows Server (no, I didn't have a choice about that)
  2. Created a repository on my github account and put my code in it
    • It's public at https://github.com/mcholl/SARS-Import/
    • You'll see I have two scripts, roottest.py and omniture-video\test.py. The code there is under patent by Apple, I'm sure 🙂
    • The idea is that I would want to run roottest.py
  3. Installed the Github plugin
  4. Created a job as follows:
  5. Manually execute the job

What I get, however, is an error message that the file cannot be located. This is strange, because I assume the workflow would be "pull a local copy of source to the …(Job)/workspace/ directory, then run the batch command in the context of the workspace directory.

Here's the full console output:

Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\jobs\Testing Github Integration\workspace
[workspace] $ cmd /c call C:\Windows\TEMP\hudson1966342425043540895.bat

C:\Program Files (x86)\Jenkins\jobs\Testing Github Integration\workspace>python roottest.py
python: can't open file 'roottest.py': [Errno 2] No such file or directory

C:\Program Files (x86)\Jenkins\jobs\Testing Github Integration\workspace>exit 2
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

Obviously I was expecting to just see the results of my print statement in the console.

What did I mess up? And why isn't my script already there?

Best Answer

For my build (on a Linux host), I do something like this (as a build step in Jenkins) to execute a build script out of the freshly-checked-out workspace:

Execute shell Command:

 sh -x $WORKSPACE/build/myproject.build

I presume it would work similar on Windows, except of course you would use \ rather than / and you're using python rather than sh to execute your script.