Rename a job

@param oldJobName existing job name.
@param newJobName The new job name.
@param crumbFlag <code>true</code> to add <b>crumbIssuer</b>
<code>false</code> otherwise.
@throws IOException In case of a failure.
7022
public JenkinsServer renameJob(String oldJobName, String newJobName, Boolean crumbFlag) throws IOException {
        renameJob(null, oldJobName, newJobName, crumbFlag);
        return this;
    }
917464
@Deprecated
  public void delete(String job, String instance) throws IOException {
    delete(job, Collections.singletonMap("instance", instance));
  }
1078971
public synchronized void failJob(JobInProgress job) {
    if (null == job) {
      LOG.info("Fail on null job is not valid");
      return;
    }

    JobStatus prevStatus = (JobStatus)job.getStatus().clone();
    LOG.info("Failing job " + job.getJobID());
    job.fail();

    // Inform the listeners if the job state has changed
    JobStatus newStatus = (JobStatus)job.getStatus().clone();
    if (prevStatus.getRunState() != newStatus.getRunState()) {
      JobStatusChangeEvent event =
        new JobStatusChangeEvent(job, EventType.RUN_STATE_CHANGED, prevStatus,
            newStatus);
      updateJobInProgressListeners(event);
    }
  }
311210
@Override public void onDeleteJob(URI deletedJobURI, String deletedJobVersion) {
    JobSpec fakeJobSpec = JobSpec.builder(deletedJobURI).withVersion(deletedJobVersion).build();
    if (this.filter.apply(fakeJobSpec)) {
      this.delegate.onDeleteJob(deletedJobURI, deletedJobVersion);
    }
  }
63213
public JobResult copyJob(String srcJobname, String dstJobName, boolean bAsProfile) {
        HttpPost postRequest = new HttpPost(baseUrl + "job/" + srcJobname);
        List<NameValuePair> nvp = new LinkedList<NameValuePair>();
        nvp.add(new BasicNameValuePair("copyTo", dstJobName));
        if (bAsProfile) {
            nvp.add(new BasicNameValuePair("asProfile", "on"));
        }
        StringEntity postEntity = null;
        try {
            postEntity = new UrlEncodedFormEntity(nvp);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        postEntity.setContentType("application/x-www-form-urlencoded");
        postRequest.addHeader("Accept", "application/xml");
        postRequest.setEntity(postEntity);
        return jobResult(postRequest);
    }
477726
private void addNewJobs(Set<HudsonJob> jobs, List<HudsonJob> existingJobs, HudsonCollector collector) {
        long start = System.currentTimeMillis();
        int count = 0;

        List<HudsonJob> newJobs = new ArrayList<>();
        for (HudsonJob job : jobs) {
            HudsonJob existing = null;
            if (!CollectionUtils.isEmpty(existingJobs) && (existingJobs.contains(job))) {
                existing = existingJobs.get(existingJobs.indexOf(job));
            }

            String niceName = getNiceName(job, collector);
            String environment = getEnvironment(job, collector);
            if (existing == null) {
                job.setCollectorId(collector.getId());
                job.setEnabled(false); // Do not enable for collection. Will be enabled when added to dashboard
                job.setDescription(job.getJobName());
                if (StringUtils.isNotEmpty(niceName)) {
                    job.setNiceName(niceName);
                }
                if (StringUtils.isNotEmpty(environment)) {
                    job.setEnvironment(environment);
                }
                newJobs.add(job);
                count++;
            } else {
                if (StringUtils.isEmpty(existing.getNiceName()) && StringUtils.isNotEmpty(niceName)) {
                    existing.setNiceName(niceName);
                    hudsonJobRepository.save(existing);
                }
                if (StringUtils.isEmpty(existing.getEnvironment()) && StringUtils.isNotEmpty(environment)) {
                    existing.setEnvironment(environment);
                    hudsonJobRepository.save(existing);
                }
                if (StringUtils.isEmpty(existing.getInstanceUrl())) {
                    existing.setInstanceUrl(job.getInstanceUrl());
                    hudsonJobRepository.save(existing);
                }
            }
        }
        //save all in one shot
        if (!CollectionUtils.isEmpty(newJobs)) {
            hudsonJobRepository.save(newJobs);
        }
        log("New jobs", start, count);
    }
280417
func (j *Jenkins) RenameJob(job string, name string) *Job {
	jobObj := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + job}
	jobObj.Rename(name)
	return &jobObj
}
561367
private void replaceByJobHandle() {
    assert state != JobState.RUNNING : "Running job cannot be replaced.";
    final Job self = this;
    new TAtomic<Job>() {
      @Override public Job atomic(Job old) {
        if( old == null ) return null;
        JobHandle jh = new JobHandle(self);
        jh.start_time = old.start_time;
        return jh;
      }
    }.fork(job_key);
  }
358429
public EngineResult createNewJob(String jobname) {
        HttpPost postRequest = new HttpPost(baseUrl);
        List<NameValuePair> nvp = new LinkedList<NameValuePair>();
        nvp.add(new BasicNameValuePair("action", "create"));
        nvp.add(new BasicNameValuePair("createpath", jobname));
        StringEntity postEntity = null;
        try {
            postEntity = new UrlEncodedFormEntity(nvp);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        postEntity.setContentType("application/x-www-form-urlencoded");
        postRequest.addHeader("Accept", "application/xml");
        postRequest.setEntity(postEntity);
        return engineResult(postRequest);
    }
1152658
public void setJobName (final String jobName)
  {
    if (jobName == null || jobName.trim ().length () == 0)
    {
      throw new IllegalArgumentException ("Job name cannot be null or empty.");
    }

    m_sJobName = jobName;
  }
485709
@Override
  public final void abortJob(org.apache.hadoop.mapreduce.JobContext context, 
                          org.apache.hadoop.mapreduce.JobStatus.State runState) 
  throws IOException {
    int state = JobStatus.getOldNewJobRunState(runState);
    if (state != JobStatus.FAILED && state != JobStatus.KILLED) {
      throw new IOException ("Invalid job run state : " + runState.name());
    }
    abortJob((JobContext) context, state);
  }
314436
public JenkinsServer updateJob(String jobName, String jobXml) throws IOException {
        return this.updateJob(jobName, jobXml, true);
    }
632950
public void rename(String newName) {
        URL url = FOLDER_INFO_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
        BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT");

        JsonObject updateInfo = new JsonObject();
        updateInfo.add("name", newName);

        request.setBody(updateInfo.toString());
        BoxJSONResponse response = (BoxJSONResponse) request.send();
        response.getJSON();
    }
932447
@Override
  public Job removeJob(final JobId id, final String token)
      throws JobDoesNotExistException, JobStillDeployedException, TokenVerificationException {
    log.info("removing job: id={}", id);
    final ZooKeeperClient client = provider.get("removeJob");
    final Job job = getJob(client, id);
    if (job == null) {
      throw new JobDoesNotExistException(id);
    }
    verifyToken(token, job);

    // TODO (dano): handle retry failures
    try {
      final ImmutableList.Builder<ZooKeeperOperation> operations = ImmutableList.builder();
      final UUID jobCreationOperationId = getJobCreation(client, id);
      if (jobCreationOperationId != null) {
        operations.add(delete(Paths.configJobCreation(id, jobCreationOperationId)));
      }
      operations.add(delete(Paths.configJobHosts(id)),
          delete(Paths.configJobRefShort(id)),
          delete(Paths.configJob(id)),
          // Touch the jobs root node so that its version is bumped on every job
          // change down the tree. Effectively, make it that version == cVersion.
          set(Paths.configJobs(), UUID.randomUUID().toString().getBytes()));
      client.transaction(operations.build());
    } catch (final NoNodeException e) {
      throw new JobDoesNotExistException(id);
    } catch (final NotEmptyException e) {
      throw new JobStillDeployedException(id, listJobHosts(client, id));
    } catch (final KeeperException e) {
      throw new HeliosRuntimeException("removing job " + id + " failed", e);
    }

    // Delete job history on a best effort basis
    try {
      client.deleteRecursive(Paths.historyJob(id));
    } catch (NoNodeException ignored) {
      // There's no history for this job
    } catch (KeeperException e) {
      log.warn("error removing job history for job {}", id, e);
    }

    return job;
  }
709698
public JenkinsServer updateJob(String jobName, String jobXml, boolean crumbFlag) throws IOException {
        return updateJob(null, jobName, jobXml, crumbFlag);
    }
178773
public void setJobName(String jobName) {

        checkFrozen();
        if (CmsStringUtil.isEmpty(jobName) || !jobName.trim().equals(jobName)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_NAME_1, jobName));

        }
        m_jobName = jobName;
    }
1341018
def add_job(self, job_name, job_id=None):
        
        logger.debug('Creating a new job named {0}'.format(job_name))
        if not self._name_is_available(job_name):
            raise DagobahError('name %s is not available' % job_name)

        if not job_id:
            job_id = self.backend.get_new_job_id()
            self.created_jobs += 1

        self.jobs.append(Job(self,
                             self.backend,
                             job_id,
                             job_name))

        job = self.get_job(job_name)
        job.commit()