         logger.info 'job on Jenkins',
           index: index
           job: element
-        if element.name.startsWith(config.jobPrefix)
+        if element.name.startsWith(templatePrefix)
           jobsFound.push new JenkinsJob(element.name, element.url)
     callback(jobsFound)
 
-# callback for API '/api/create-jobs/:id'
+# callback for API '/api/create-jobs'
 exports.create_jobs = (req, res) ->
   logger.info 'main#create_jobs',
     body: req.body

  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)

