       statusCode: response.statusCode
 
 # get all jobs that start with config.expectedJobPrefix
+# param: jenkinsUrl => the base url to the jenkins server
+# param: templatePrefix => the prefix for the templates to search for on the server
 # param: callback(jobsFound)
-get_template_jobs = (jenkinsUrl, callback) ->
+get_template_jobs = (jenkinsUrl, templatePrefix, callback) ->
   urlParams = '/api/json'
   requestUrl = url.resolve(jenkinsUrl, urlParams)
   logger.info 'main#get_template_jobs',

  if _.isNull(jenkinsUrl) || _.isUndefined(jenkinsUrl)
    jenkinsUrl = config.defaultJenkinsUrl

  get_template_jobs jenkinsUrl, (jobsFound) ->
    logger.info 'jobs found =>',
      jobs: jobsFound

    _.each jobsFound, (element, index, list) ->
      copy_job_from_template(req.body.jobPrefix, element.name, jenkinsUrl)

  res.send 200

require './string_ext'

# create a new job using another job as a template
copy_job_from_template = (templatePrefix, newJobPrefix, copyFrom, jenkinsUrl) ->
  logger.info 'main#copy_job_from_template',
    newJobPrefix: newJobPrefix
    copyFrom: copyFrom
    jenkinsUrl: jenkinsUrl

  newJobName = newJobPrefix + copyFrom.slice(templatePrefix.length)
  urlParams = '/createItem?name=' + newJobName + '&mode=copy&from=' + copyFrom
  createUrl = url.resolve(jenkinsUrl, urlParams)

