/** * This method is called whenever the Job form is saved. We use the 'on' property * to determine if the controls are selected. * * @param req - The request * @param form - A JSONObject containing the submitted form data from the job configuration * @return a {@link JobProperty} object representing the tagging added to the job * @throws hudson.model.Descriptor.FormException if querying of form throws an error */ @Override public JobProperty<?> reconfigure(StaplerRequest req, @Nonnull JSONObject form) throws Descriptor.FormException { DatadogJobProperty prop = (DatadogJobProperty) super.reconfigure(req, form); System.out.println(form); boolean isEnableFile = form.getBoolean("enableFile"); boolean isEnableTagProperties = form.getBoolean("enableProperty"); if(!isEnableFile) { prop.tagFile = null; prop.emitOnCheckout = false; } if(!isEnableTagProperties) { prop.tagProperties = null; } return prop; }
/** * This method will fetch all properties defined for the current project * and only those defined on it. * <p> * There are two complications though: * <ol> * <li> * {@link ParametersDefinitionProperty} instances need to be replaced * with {@link InheritanceParametersDefinitionProperty} instances, * to make sure that versioning details are correctly stored. * Also, we wish to make sure that the more advanced Jelly-files from * the latter class are used for build-purposes. * </li> * <li> * Variances define additional properties; so that we can make sure * to splice-in those additional properties if a request for * parameters comes from a direct child with the correct variance. * </li> * </ol> * <p> * Also note, that Jenkins does not allow direct access to the properties * list. So clearing or modifying this list will not work. * * @return the local list of properties. */ public List<JobProperty<? super InheritanceProject>> getRawAllProperties() { LinkedList<JobProperty<? super InheritanceProject>> out = new LinkedList<JobProperty<? super InheritanceProject>>(); //First, we add the global properties defined for this project List<JobProperty<? super InheritanceProject>> origProps = super.getAllProperties(); //Filling the output list with the adjusted original properties for (JobProperty<? super InheritanceProject> prop : origProps) { if (!(prop instanceof ParametersDefinitionProperty)) { out.add(prop); continue; } //Converting a PDP to an IPDP ParametersDefinitionProperty pdp = (ParametersDefinitionProperty) prop; InheritanceParametersDefinitionProperty ipdp = new InheritanceParametersDefinitionProperty( pdp.getOwner(), pdp ); out.add(ipdp); } return out; }
@Override public JobProperty<?> merge( JobProperty<?> prior, JobProperty<?> latter, InheritanceProject caller) { if (!(prior instanceof ParametersDefinitionProperty) || !(latter instanceof ParametersDefinitionProperty)) { return latter; } InheritanceParametersDefinitionProperty ipdp = InheritanceParametersDefinitionProperty .createMerged( (ParametersDefinitionProperty) prior, (ParametersDefinitionProperty) latter ); return ipdp; }
@Override public JobProperty<?> newInstance(StaplerRequest request, JSONObject formData) throws FormException { if (formData.size() > 0 && formData.has("useTemplate")) { JSONObject useTemplate = formData.getJSONObject("useTemplate"); String templateJobName = useTemplate.getString("templateJobName"); boolean syncMatrixAxis = useTemplate.getBoolean("syncMatrixAxis"); boolean syncDescription = useTemplate.getBoolean("syncDescription"); boolean syncBuildTriggers = useTemplate.getBoolean("syncBuildTriggers"); boolean syncDisabled = useTemplate.getBoolean("syncDisabled"); boolean syncSecurity = useTemplate.getBoolean("syncSecurity"); boolean syncScm = useTemplate.getBoolean("syncScm"); boolean syncOwnership = useTemplate.getBoolean("syncOwnership"); boolean syncAssignedLabel = useTemplate.getBoolean("syncAssignedLabel"); return new TemplateImplementationProperty(templateJobName, syncMatrixAxis, syncDescription, syncBuildTriggers, syncDisabled, syncSecurity, syncScm, syncOwnership, syncAssignedLabel); } return null; }
public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { GogsProjectProperty tpp = req.bindJSON( GogsProjectProperty.class, formData.getJSONObject(GOGS_PROJECT_BLOCK_NAME) ); if ( tpp != null ) { LOGGER.info(formData.toString()); LOGGER.info(tpp.gogsSecret); gogsSecret = tpp.gogsSecret; } return tpp; }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (formData.isNullObject()) return null; JSONObject containersDefinition = formData.getJSONObject("containersDefinition"); if (containersDefinition.isNullObject()) return null; return req.bindJSON(ContainerSetDefinition.class, containersDefinition); }
public Map<JobPropertyDescriptor, JobProperty<? super InheritanceProject>> getProperties(IMode mode) { List<JobProperty<? super InheritanceProject>> lst = this.getAllProperties(mode); if (lst == null || lst.isEmpty()) { return Collections.emptyMap(); } HashMap<JobPropertyDescriptor, JobProperty<? super InheritanceProject>> map = new HashMap<JobPropertyDescriptor, JobProperty<? super InheritanceProject>>(); for (JobProperty<? super InheritanceProject> prop : lst) { map.put(prop.getDescriptor(), prop); } return map; }
public List<JobProperty<? super InheritanceProject>> getAllProperties(IMode mode) { //Fetching the variance of the current project; it is necessary //to access the correct compatibility setting in the correct parent final InheritanceProject rootProject = this; InheritanceGovernor<List<JobProperty<? super InheritanceProject>>> gov = new InheritanceGovernor<List<JobProperty<? super InheritanceProject>>>( "properties", SELECTOR.PARAMETER, this) { @Override protected List<JobProperty<? super InheritanceProject>> castToDestinationType(Object o) { return castToList(o); } @Override public List<JobProperty<? super InheritanceProject>> getRawField( InheritanceProject ip) { return ip.getRawAllProperties(); } @Override protected List<JobProperty<? super InheritanceProject>> reduceFromFullInheritance( Deque<List<JobProperty<? super InheritanceProject>>> list) { //First, we add the variances for the root project InheritanceParametersDefinitionProperty variance = rootProject.getVarianceParameters(); if (variance != null) { List<JobProperty<? super InheritanceProject>> varLst = new LinkedList<JobProperty<? super InheritanceProject>>(); varLst.add(variance); list.addLast(varLst); } return InheritanceGovernor.reduceByMerge( list, JobProperty.class, this.caller ); } }; return gov.retrieveFullyDerivedField(this, mode); }
public JobProperty getProperty(String className, IMode mode) { for (JobProperty p : this.getAllProperties(mode)) { if (p.getClass().getName().equals(className)) { return p; } } return null; }
public Collection<?> getOverrides(IMode mode) { List<Object> r = new ArrayList<Object>(); for (JobProperty<? super InheritanceProject> p : this.getAllProperties(mode)) { r.addAll(p.getJobOverrides()); } return r; }
/** * This needs to be overridden, because {@link AbstractProject} reads the * properties field directly; which circumvents inheritance. */ @Override public List<SubTask> getSubTasks() { List<SubTask> r = new ArrayList<SubTask>(); r.add(this); for (SubTaskContributor euc : SubTaskContributor.all()) { r.addAll(euc.forProject(this)); } for (JobProperty<?> p : this.getAllProperties()) { r.addAll(p.getSubTasks()); } return r; }
@Override public String getObjectIdentifier(JobProperty<?> obj) { //All regular and inheritable parameter definitions are the same, as //there should be only one! if (obj.getClass() == ParametersDefinitionProperty.class || obj.getClass() == InheritanceParametersDefinitionProperty.class) { return "SINGLETON"; } else { return null; } }
/** * This method makes sure that only * {@link InheritanceParametersDefinitionProperty} objects are stored in * the list returned to Jenkins and that they are all owned by the caller. * This means that it will convert+copy objects that do not match this * and will make sure that the correct scoping is set for each new * {@link InheritanceParametersDefinitionProperty} object. */ @Override public JobProperty<?> handleSingleton( JobProperty<?> jp, InheritanceProject caller) { boolean needsCopy = false; if (!(jp instanceof ParametersDefinitionProperty)) { return jp; } ParametersDefinitionProperty pdp = (ParametersDefinitionProperty) jp; //Checking if we already deal with an IPDP if (pdp instanceof InheritanceParametersDefinitionProperty) { //Checking if the caller already owns the IPDP; if not we copy if (pdp.getOwner() != caller) { needsCopy = true; } } else { needsCopy = true; } if (needsCopy) { InheritanceParametersDefinitionProperty ipdp = new InheritanceParametersDefinitionProperty( (caller != null) ? caller : pdp.getOwner(), pdp ); return ipdp; } else { return pdp; } }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { TransifexProjectProperty tpp = req.bindJSON(TransifexProjectProperty.class, formData); if (tpp.projectUrl == null) { tpp = null; // not configured } return tpp; }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { YouTrackProjectProperty ypp = req.bindParameters(YouTrackProjectProperty.class, "youtrack."); if (ypp.siteName == null) { ypp = null; } return ypp; }
public static Collection<AbstractProject> findProjectsWithProperty(final Class<? extends JobProperty<?>> property) { List<AbstractProject> projects = Jenkins.getInstance().getAllItems(AbstractProject.class); return Collections2.filter(projects, new Predicate<AbstractProject>() { @Override public boolean apply(AbstractProject abstractProject) { return abstractProject.getProperty(property) != null; } }); }
@Override public JobProperty<?> newInstance(StaplerRequest request, JSONObject formData) throws FormException { if (formData.size() > 0) { return new TemplateProperty(); } return null; }
default EnvVars buildEnvVars() { EnvVars allOverrides = new EnvVars(EnvVars.masterEnvVars); // when running outside of an openshift pod, global env vars like // SKIP_TLS will not exist in master env vars if (Jenkins.getInstance().getGlobalNodeProperties() != null) { if (Jenkins.getInstance().getGlobalNodeProperties() .get(hudson.slaves.EnvironmentVariablesNodeProperty.class) != null) { if (Jenkins .getInstance() .getGlobalNodeProperties() .get(hudson.slaves.EnvironmentVariablesNodeProperty.class) .getEnvVars() != null) { allOverrides .putAll(Jenkins .getInstance() .getGlobalNodeProperties() .get(hudson.slaves.EnvironmentVariablesNodeProperty.class) .getEnvVars()); } } } String[] reqPieces = Stapler.getCurrentRequest().getRequestURI() .split("/"); if (reqPieces != null && reqPieces.length > 2) { for (Job j : Jenkins.getInstance().getAllItems(Job.class)) { if (j.getName().equals(reqPieces[2])) { List<JobProperty> jps = j.getAllProperties(); for (JobProperty jp : jps) { if (jp instanceof ParametersDefinitionProperty) { ParametersDefinitionProperty prop = (ParametersDefinitionProperty) jp; for (ParameterDefinition param : prop .getParameterDefinitions()) { allOverrides.put(param.getName(), param .getDefaultParameterValue().getValue() .toString()); } } } } } } return allOverrides; }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { return super.newInstance(req, formData); }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { return req.bindJSON(GitLabConnectionProperty.class, formData); }
/** * Test persisting jobs with parameters. * * @throws Exception in Jenkins rule */ @Test public void testSaveParameters() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); GroovyScript scriptParam001 = new GroovyScript(new SecureGroovyScript(SCRIPT_PARAM001, false, null), new SecureGroovyScript(SCRIPT_FALLBACK_PARAM001, false, null)); ChoiceParameter param001 = new ChoiceParameter("param001", "param001 description", "random-name", scriptParam001, AbstractUnoChoiceParameter.PARAMETER_TYPE_SINGLE_SELECT, true, 1); GroovyScript scriptParam002 = new GroovyScript(new SecureGroovyScript(SCRIPT_PARAM002, false, null), new SecureGroovyScript(SCRIPT_FALLBACK_PARAM002, false, null)); CascadeChoiceParameter param002 = new CascadeChoiceParameter("param002", "param002 description", "random-name", scriptParam002, AbstractUnoChoiceParameter.PARAMETER_TYPE_SINGLE_SELECT, "param001", true, 1); ParametersDefinitionProperty param001Def = new ParametersDefinitionProperty( Arrays.<ParameterDefinition>asList(param001, param002)); project.addProperty(param001Def); QueueTaskFuture<FreeStyleBuild> future = project.scheduleBuild2(0); FreeStyleBuild build = future.get(); // even though the cascaded parameter will fail to evaluate, we should // still get a success here. assertEquals(Result.SUCCESS, build.getResult()); XmlFile configXml = project.getConfigFile(); FreeStyleProject reReadProject = (FreeStyleProject) configXml.read(); int found = 0; for (Entry<JobPropertyDescriptor, JobProperty<? super FreeStyleProject>> entry : reReadProject.getProperties() .entrySet()) { JobProperty<? super FreeStyleProject> jobProperty = entry.getValue(); if (jobProperty instanceof ParametersDefinitionProperty) { ParametersDefinitionProperty paramDef = (ParametersDefinitionProperty) jobProperty; List<ParameterDefinition> parameters = paramDef.getParameterDefinitions(); for (ParameterDefinition parameter : parameters) { if (parameter instanceof AbstractScriptableParameter) { found++; AbstractScriptableParameter choiceParam = (AbstractScriptableParameter) parameter; String scriptText = ((GroovyScript) choiceParam.getScript()).getScript().getScript(); String fallbackScriptText = ((GroovyScript) choiceParam.getScript()).getFallbackScript() .getScript(); assertTrue("Found an empty script!", StringUtils.isNotBlank(scriptText)); assertTrue("Found an empty fallback script!", StringUtils.isNotBlank(fallbackScriptText)); if (parameter.getName().equals("param001")) { assertEquals(SCRIPT_PARAM001, scriptText); assertEquals(SCRIPT_FALLBACK_PARAM001, fallbackScriptText); } else { assertEquals(SCRIPT_PARAM002, scriptText); assertEquals(SCRIPT_FALLBACK_PARAM002, fallbackScriptText); } } } } } // We have two parameters before saving. We must have two now. assertEquals("Didn't find all parameters after persisting xml", 2, found); }
@Override public <T extends JobProperty> T getProperty(final Class<T> clazz) { return getParent().getProperty(clazz); }
/** * This method implements the actual association of a set of objects with * a given version. * <p> * Subclasses should override this method, call the super() implementation * and then associate their own fields with that version by calling * {@link VersionedObjectStore#setObjectFor(Version, String, Object)}. * * @param v the version to archive settings for. Must never be null. */ protected void dumpConfigToVersion(Version v) { //Storing the list of parents this.versionStore.setObjectFor( v, "parentReferences", new LinkedList<AbstractProjectReference>(this.getRawParentReferences()) ); //Storing the list of compatibility matings -- also contains //the parameters defined on them. this.versionStore.setObjectFor( v, "compatibleProjects", new LinkedList<AbstractProjectReference>(this.compatibleProjects) ); //Storing the properties of this job; this contains the project parameters this.versionStore.setObjectFor( v, "properties", new LinkedList<JobProperty<? super InheritanceProject>>( super.getAllProperties() ) ); //Storing build wrappers this.versionStore.setObjectFor( v, "buildWrappersList", new DescribableList<BuildWrapper, Descriptor<BuildWrapper>>( NOOP, super.getBuildWrappersList().toList() ) ); //Storing builders this.versionStore.setObjectFor( v, "buildersList", new DescribableList<Builder, Descriptor<Builder>>( NOOP, super.getBuildersList().toList() ) ); //Storing publishers this.versionStore.setObjectFor( v, "publishersList", new DescribableList<Publisher, Descriptor<Publisher>>( NOOP, super.getPublishersList().toList() ) ); //Storing actions this.versionStore.setObjectFor( v, "actions", new LinkedList<Action>(super.getActions()) ); //Storing the other, more simple properties this.versionStore.setObjectFor(v, "scm", super.getScm()); this.versionStore.setObjectFor(v, "quietPeriod", this.getRawQuietPeriod()); this.versionStore.setObjectFor(v, "scmCheckoutRetryCount", this.getRawScmCheckoutRetryCount()); this.versionStore.setObjectFor(v, "scmCheckoutStrategy", super.getScmCheckoutStrategy()); this.versionStore.setObjectFor(v, "blockBuildWhenDownstreamBuilding", super.blockBuildWhenDownstreamBuilding()); this.versionStore.setObjectFor(v, "blockBuildWhenUpstreamBuilding", super.blockBuildWhenUpstreamBuilding()); this.versionStore.setObjectFor(v, "logRotator", super.getBuildDiscarder()); this.versionStore.setObjectFor(v, "customWorkspace", super.getCustomWorkspace()); this.versionStore.setObjectFor(v, "parameterizedWorkspace", this.getRawParameterizedWorkspace()); }
@Override public Map<JobPropertyDescriptor, JobProperty<? super InheritanceProject>> getProperties() { return this.getProperties(IMode.AUTO); }
/** * {@inheritDoc} */ @Override @Exported(name="property",inline=true) public List<JobProperty<? super InheritanceProject>> getAllProperties() { return this.getAllProperties(IMode.AUTO); }
/** * {@inheritDoc} */ @Override public <T extends JobProperty> T getProperty(Class<T> clazz) { return this.getProperty(clazz, IMode.AUTO); }
/** * {@inheritDoc} */ @Override public JobProperty getProperty(String className) { return this.getProperty(className, IMode.AUTO); }
@Override public boolean isApplicableFor( Class<?> clazz) { return JobProperty.class.isAssignableFrom(clazz); }