I have an existing job A1a1 at:
D:\Jenkins-Slave\workspace\scp\A\1\a1\A1a1
Now I want to create a new job:
D:\Jenkins-Slave\workspace\scp\B\1\B1
and B1 should be defined as "copy from" A1a1.
I have tried to refer to A1a1 in the "Copy from" field in different ways:
../../A/1/a1/A1a1
..\..\A\1\a1\A1a1
D:\Jenkins-Slave\workspace\scp\A\1\a1\A1a1
None of them works with Error "No such job..."
Edit: I have also used the URL in the copy from field, id does not work and returns the same error.
What is the way to refer a job that is not a sibling of the job to be created?
Related
In Jenkins parameterized project, is there a way to receive the variable in different name?
for e.g:
JOB_A:
sends parameter FOO='myfoo' when it calls JOB_B
JOB_B:
Is there a way to receive it on different name, say 'BAR', so it will be BAR='myfoo', I know this can be done with BAR=$FOO in Build/Execute shell, I am here to find if there is any option to do this in General/This project is parameterized section.
On JOB_A, in 'Trigger/call builds on other progects' find 'Predefined Parameters' from 'Add Parameters' drop-down. You just want to put this:
BAR=${FOO}
Click to see the screenshot
I have a Jenkins parameterized build. I tick the "this build is parameterized" and I set a "Choice" environment name to be "ENVIRONMENT" and then as choices I define human readable names such as "Test env1", "Test env2", etc. However I want these keys to actually contain different values, for example "Test env1" key would container a file path as its value. How can this be done?
I have managed to get the keys/values with a dropdown select parameter working with the Active Choices Plugin, the answer was actually buried in the comments on the plugin page itself.
You simply need to use a map rather than a list when writing your groovy script to define the dropdown options. The map key is what the parameter will be set to if the user selects this option. The map value is what will be actually displayed to the user (i.e something human readable) in the dropdown list.
Here are the steps.
Ensure you have the Active Choices Plugin installed.
Open the configuration of your Jenkins job, select This project is parameterised.
Click Add Parameter and select Active Choices Parameter.
Name your parameter ENVIRONMENT and click the Groovy Script check box.
In Groovy Script enter content: return ['env1 file path value':'Test env1', 'env2 file path value':'Test env2'] For this example the user will see a dropdown with 2 options: Test env1 and Test env2. The keys: env1 file path value and env2 file path value are what the Jenkins build parameter will be set to if the option is selected. Modify these as necessary.
In this case ENVIRONMENT is the key and "Test env1", "Test env2", etc. are the possible values. Choice parameter is to restrict the possible inputs.
Based on the value of %ENVIRONMENT% you can execute multiple pathways in your batch scripts or whichever scripts you are executing
Is there any documentation/examples on the Copy Artifacts Plugin, namely the "Specified by a build parameter" option?
I'm trying to do a "join-diamond" pipeline such as in this SO question and can't figure out what to put in the Parameter Name option of the "Copy artifacts from another project" build step to get my artifacts copied properly.
All my jobs have a PL_BUILD_NUMBER parameter and I'd like to use it to select which build to copy the artifacts from.
This mailing list post says the parameter must be an XML. So I tried this :
BUILD_SELECTOR=<SpecificBuildSelector><buildNumber>$PL_BUILD_NUMBER</buildNumber></SpecificBuildSelector>
but it did not work. I get this exception in the log:
java.lang.NullPointerException
at java.io.StringReader.<init>(Unknown Source)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1035)
at hudson.plugins.copyartifact.BuildSelectorParameter.getSelectorFromXml(BuildSelectorParameter.java:80)
at hudson.plugins.copyartifact.ParameterizedBuildSelector.getBuild(ParameterizedBuildSelector.java:52)
at hudson.plugins.copyartifact.CopyArtifact.perform(CopyArtifact.java:280)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:772)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:160)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:535)
at hudson.model.Run.execute(Run.java:1740)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:233)
What should I put?
There's also the "This build is parametrized --> Build selector for Copy Artifact" that I don't know if I should use it...
Thanks!
You are mixing Specified by a build parameter and Specific build. It's not clear which one you are asking about.
For Specified by a build parameter, you need to configure in two places:
Under "This build is parameterized", select "Build selector for Copy Artifact"
The Name of this parameter is what we will give to Copy Artifact build step later.
From the UI perspective, user will be prompted with a build selector interface (which allows all types of selections: last build, specific build, latest promoted, etc, etc).
On the "Copy Artifact" build step, under "Which build", select "Specified by a build parameter".
It will display another field called "Parameter Name" (with default being BUILD_SELECTOR).
That is the Name of the "Build selector for Copy Artifact" parameter that we created earlier.
Since default is BUILD_SELECTOR, if you called your parameter BUILD_SELECTOR as well, you don't need to change anything.
The value of BUILD_SELECTOR parameter will change greatly based on what you select at parameter screen just before build. You can see its possible values by printing the value of the parameter as a test (echo %BUILD_SELECTOR% on Windows, echo $BUILD_SELECTOR on *nix) and then manually running the build and trying different selectors.
Specifically, the value of:
<SpecificBuildSelector><buildNumber>123</buildNumber></SpecificBuildSelector>
will be used when the user selects Specific build on the parameter screen, and enters value 123
If you need to set this parameter value from outside the job (for example from a script or Parameterized Trigger plugin) you would need to follow this particular structure, depending on the type of the selection you want.
Edit: After re-reading your question and your actual requirement (which is not what the question title is)
In your case, you don't need "Build selector for Copy Artifact" parameter. You just need:
Copy Artifacts build step
Enter Project name to copy from
Under Which build, select Specific build
Under Build number, type $PL_BUILD_NUMBER (which you say you already have in the job)
I have Job on Jenkins ver. 1.500 with build ID parameterized.
I want to use this parameterized value in the subject line of section "Post-build Actions".
If I try to access using $ID or ${ID} its printing it as plane string "$ID"[without value substitution]. I am aware of environmental variable $BUILD_NUMBER, which is giving the current job #number.
Can someone share, how to achieve this simple task of reading build number?
$PROJECT_NAME - Job # $ID built at $BUILD_ID - $BUILD_STATUS!
--Thanks,Prashant
It sounds like you are talking about Editable Email Notification post-build action. It has it's own way of referencing variables.
Variables that are available within the plugin, can be referenced directly as ${VARIABLE}, in both the body of the email and the subject line. For a list of available variables, click on the ? icon for on-page help.
However to access other environmental variables, including the parameters used by the build, you have to use the format ${ENV, var="VARIABLE"}, so in your case, it would be ${ENV, var="ID"}
I have a job that when it finishes (Post build Actions) Triggers a parameterized build (Job A)
The build that is getting triggered sets a string parameter called foo for the value of JOB_NAME
"Job A" has a build step to 'copy artifacts from another project' were I set the project name to the variable i'm passing (%foo%)
I can confirm that %foo% is getting the correct value however when the build step executes it fails to substitute the variable
This is the error message I'm getting
Unable to find project for artifact copy: %foo%
I'm looking for alternatives to solve my problem which is
How to pass dynamically project name for copy artifacts from another project
Did you check the help for Copy artifacts build step? If you click on the question mark next to the Project name field, you will see this text:
Name of source project for copying of artifact(s). May contain references to build parameters like $PARAM (note that when a parameter is used, the source project must be accessible to all authenticated users; this prevents use of parameters to access artifacts of private jobs)
So, you should try $foo instead of %foo%.
Had a similar problem.
The "Question mark text" on Project name that #sti quoted was changed meanwhile and only displays info for maven modules.
The error message i got:
Unable to find project for artifact copy: XYZ
This may be due to incorrect project name or permission settings; see help for project name in job configuration.
gives you a hint about missing permissions, but it might be hard to catch or understand (what kind of project-permission?).
So what was missing for me:
Go into your "source"-Job/Project where you want to copy artifacts FROM, and check that
Permission to Copy Artifact
is correctly set to the job you want to copy INTO. (Or set to a wildcard like *).
For those using jenkins-job-builder, you can set the required permissions like so:
- job:
name: project-to-copy-from
properties:
- copyartifact:
projects: "*"
Then you can use copyartifact like so:
- job:
name: project-to-copy-to
builders:
- copyartifact:
project: project-to-copy-from
which-build: last-successful
http://docs.openstack.org/infra/jenkins-job-builder/properties.html#properties.copyartifact