I have a project that should at the end send an email with a file.
During the build i have the following env.variable:
$TARGET_INDEX=/.../.../.../index.html
In the "Editable Email Notification" i have configured:
Content Type - HTML
Default Content - ${FILE,path="${TARGET_INDEX}"}
But at the end of the build I got the below trace:
+ TARGET_INDEX=/.../.../.../index.html
[EnvInject] - Injecting environment variables from a build step.
[EnvInject] - Injecting as environment variables the properties file path 'tmp_default.properties'
[EnvInject] - Variables injected successfully.
No emails were triggered.
I can't understand why no email was triggered!?
Any clue? Do you have another approach to send email with HTML as content?
Editable Email Notification has an Attachment section and it use Ant script.when you require an email trigger at the end of your build including file as an attachment then it will help full for you to know Ant script work mainly on relative addressing rather than absolute addressing. so content in attachment pattern should be some thing like this
**/foldername/*.txt
(anyextension)
Note:make sure the floder exists in your job workspace and your index.html is placed in that folder.
Hope this helps to some extent
You need to check the Triggers section, which will be hidden by default.
You need to click the "Advanced Settings" button to show this section.
Related
I'm attaching a template in email using Jenkins. I've created a folder name email-templates under .jenkins and there I've placed my template with the name build-report.groovy.
Good thing is i can attach this template in email ext using ${SCRIPT, template="build-report.groovy"} and i can see the expected data in email.
But if i use ${SCRIPT, template="groovy-html.template"} i can also see the same template data with colors and styles.
I didn't have any template file with name groovy-html.template then from where Jenkins picked ?
It's a part of email-ext Jenkins plugin and it's located inside of corresponding jar file.
You can see it in the source code:
https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/groovy-html.template
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"}
Can I display the contents of another file in my jelly script output?
If the file is included in the workspace of the job, declare your variable such as:
<j:set var="fileContent" value="${build.getWorkspace().child("results.html")}"/>
And call it this way:
${fileContent}
Yes, you can use the ${FILE, path} token to include the contents of a file (path is relative to your workspace directory).
This info is taken from the Content Token Reference in the email-ext part of your job configuration. Click the question mark on the right to get the full list of tokens.
Look at util:loadText which is a "tag which loads text from a file or URI into a Jelly variable."
<u:loadText var="contents" file="${filename}"/>
${contents}
Haven't used it inside of Jenkins before... let us know if it works.
I have Jenkins job that has execute shell part in which I have some variable
BUILD that is dynamically populated.
After build execution, I want to pass this variable to email-ext plugin Default Content to able to show it's value.
I've tried couple of ways without a success:
Passing this ${BUILD} value in Default Content is not recognized (Only Jenkins environment variables are visible in this context)
Defined new Jenkins global environment variable and tried to overwrite its initial value in shell context which apparently is not possible
Any idea on how to do this?
In my case, I'm not the administrator, then I can't install plugins. But can be done with a workaround.
In Content Token Reference help you can found an useful tool.
${PROPFILE,file="FILENAME",property="PROPERTYNAME"}
Expands to the value of a property in a property file. The filename is
relative to the build workspace root.
Then save values in a property file inside Build > Execute Shell:
rm -f ${WORKSPACE}/env.properties
touch ${WORKSPACE}/env.properties
store="/opt/current/store"
echo "store.folder=${store}" >> ${WORKSPACE}/env.properties
echo "${store}"
And read it from Post-build Actions > Editable Email Notification with:
${PROPFILE,file="env.properties",property="store.folder"}
Simple and easy:
In your "Execute Shell"
echo "test log" > /some/file/path/logFile.txt
Then in your "Editable Email Notification-Default Content"
${FILE,path="/some/file/path/logFile.txt"}
Build and you will receive a email with content "test log"
To see more email tokens, you can click the question mark beside "Content Token Reference" in "Editable Email Notification" section.
Use EnvInject Plugin to read the variable from a file, after you write that file in the "shell part".
In general, environment variables never go from child process back to parent process, this is basic feature of both Windows and Unix operating system families. Child always gets a copy of parent's environment, and if it modifies it, it modifies it's own copy (which is then copied to any child process if it launches any, etc). But to get changes back, some other method must be used, such as child writing desired changes to a file, which is then parsed by parent, which can then edit it's own environment based on it.
You can pass build parameters to email ext plugin by using:
${ENV,var="CAPITALIZED:VAR_NAME"}
In that way i see the variable value in the received mail.
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