14

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?

Affable Geek
  • 241
  • 1
  • 2
  • 6
  • Lets see the code from C:\Windows\TEMP\hudson1966342425043540895.bat are you using git pull? –  Aug 13 '13 at 17:25
  • Jenkins automatically creates then deletes it. You can see the full contents in the console output, however - it's the "python roottest.py" command I referenced above – Affable Geek Aug 13 '13 at 17:34
  • roottest.py is not in your path. Do you see the file in the workspace directory or is that automatically deleted as well? When you run git pull you need to be in the local copy of the cloned repository I believe, it should then pull any new changes into the local repo. It is hard to help you when I cannot see any of the actual commands being run. –  Aug 13 '13 at 17:40
  • Did you follow these instructions for the github plugin https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin- ? Did you set the GIT_HOME environmental variable etc? –  Aug 13 '13 at 17:44
  • D'oh! One more reason to hate windows. Thank you - I think that may be the issue – Affable Geek Aug 13 '13 at 17:46

3 Answers3

5

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.

eric.green
  • 385
  • 1
  • 4
4

You can write two lines in your build:

chmod 777 ./my_script.sh
./my_script.sh
GregL
  • 9,030
  • 2
  • 24
  • 35
Andrs Zam
  • 51
  • 1
0

You could store some script in Git, e.g. test.sh:

#!/bin/bash
_test_func(){ 
 echo 'test'
}

Then in "Execute shell" input, put import of that script and call "_test_func":

source test.sh
_test_func

Result:

 + source test.sh
 + _test_func
 test
Raf
  • 101
  • 1