0

We have a Jenkins server where I have already defined my job. It uses Perforce as SCM.

I would like to replicate all the steps that Jenkins takes to build the project but use the files in my local workspace instead. Basically, I would like to run a jenkins build locally based on a job defined on another server.

How would I do the same?

sgarg
  • 2,340
  • 5
  • 30
  • 42

3 Answers3

1

Something like what I created for my Perforce users might work for you -- I added a job in Jenkins that will grab shelved files (so, the user would need to shelve the files), create a build from there, then let the user know if it was successful (they also have the option of running tests or creating a deployable build). The gist of it is to request the shelved changelist #, then do this: "p4 unshelve -s %SHELVEDCL% " and proceed as usual. They use it when they feel like it; it's been useful. But it does require access to Jenkins.

tkosinski
  • 1,631
  • 13
  • 17
  • Thanks this basically solves my basic problem which was having my local changes build without submitting to perforce. – sgarg Jan 20 '16 at 15:50
  • 1
    I tried this. It works great! The only thing someone might want to add to this is "p4 revert //..." before running the unshelve, otherwise the Jenkins workspace is out of sync with head. – sgarg Mar 08 '16 at 20:24
  • Yes, absolutely! I found this out the hard way. Thank you! – tkosinski Mar 08 '16 at 20:37
0

1) Install Jenkins on your local workstation (if you have no already done so).

2) Copy the /Jenkins/jobs/ directory to the /Jenkins/jobs/ directory on your local workstation.

3) Fire it up and edit the Perforce workspace (and any other settings) as necessary.

tkosinski
  • 1,631
  • 13
  • 17
  • is there a simpler way to do this without running my own jenkins server? Like something which can run the jenkins job as a one time operation without running the server all the time? – sgarg Dec 04 '15 at 15:10
  • Without knowing anything about your build environment, I'd have to say almost surely it can be done without running your own Jenkins server. Leave Jenkins out of the picture entirely and set it up to run manually. Jenkins is quite nifty for doing a lot of things, but why bother with the overhead if all you want to do is the occasional manual build? – tkosinski Dec 07 '15 at 17:10
  • I'm just trying to perform the build steps of our Jenkins server locally, for producing dev builds locally. It's basically MSBUILD, with Nuget restore before it, but there's the artifacts creation process which is hidden from me. Shouldn't there be a way to generate a makefile sort of thing from a jenkins job? – sgarg Dec 07 '15 at 21:05
  • I think that's the sort of thing Jenkins is trying to keep you from having to do. – tkosinski Dec 08 '15 at 15:57
  • Maybe, but wouldn't I want a build system where I can produce a build locally similar to how it would be done by my build server? Why should I have to wait to submit code, have the server make the build, deploy it and only then find out my program has a runtime error or something I want to change about it? It's a waste of commits, code reviews and time. :) – sgarg Dec 08 '15 at 21:22
  • Right. If you want to test your build before submitting, you don't want your build to be syncing from Perforce, but just want to kick off a build using your local files. In other words, you don't want to be building the exact same way as your build server (i.e., getting the files from Perforce). – tkosinski Dec 09 '15 at 16:46
  • yup, I don't want to use the files from Perforce, but I do want to use the build configuration from Jenkins - 1. To use the build artifacts for our deployment tool. 2. To avoid inconsistencies between local build and server builds. That's basically my question - substituting perforce files in a jenkins build with local files. – sgarg Dec 10 '15 at 15:13
  • 1
    Ah, got it. Something like what I created for my Perforce users might work for you -- I added a job in Jenkins that will grab shelved files (so, the user would need to shelve the files), create a build from there, then let the user know if it was successful (they also have the option of running tests or creating a deployable build). The gist of it is to request the shelved changelist #, then do this: "p4 unshelve -s %SHELVEDCL% " and proceed as usual. They use it when they feel like it; it's been useful. But it does require access to Jenkins. – tkosinski Dec 10 '15 at 15:48
0

IMO, you should probably takes these steps:

  1. Create a new Jenkins job from the existing one. 2) Modify the job to be a string "parameterized" job where you pass branch-name as the parameter. You can do using "This build is parameterized" option in the configuration of the job. 3) Under the configuration of the job, for Source Code Management section, change the Branch Specifier to use the String Parameter variable name (created from #2 above). 4) Create your feature branch on Perforce and make intended changes there. 5) Run the newly created job with your branch as the parameter to it.

Hope this helps.

  • Your answer does touch on the ultimate purpose of my question which is to build and test new features, but I want to know if it's possible without creating a lot of branches. – sgarg Dec 08 '15 at 15:05