I want to configure a parametrized job in jenkins, who manipulate file:
parameters([
file(defaultValue: 'DEFAULT', name : 'tomcatCodesUrl' , description: 'URL of service where to find tomcat mapping json file'),
the issus is , this parameter only return the name of the file. how can I acces to this content?
Currently there is no easy way to do this. You can find discussion about this in JENKINS-27413
Yeah that parameter is as redundant as it can be. Might aswell just use string.
Anyway. You can get the files content with readFile:
def content = readFile encoding: 'utf-8', file: 'tomcatCodesUrl'
How to use file parameter in jenkins
This post might be helpful. The upshot is, when users upload a file, it will be saved into the root directory of the project's workspace. You can directly access the file using any programming language you like, given the file name. The file content is not returned to you as a parameter, but anyway, since you know its saved place (workspace dir) and file name, you are in control.
Related
I wanted to allow users to select a folder path as a parameter and get the entire folder path as the parameter value. Is there any plugin for this purpose.
I have explored the File Parameter, this allows to select a file path and gives only the file name as output and not the path.
I also explored the File systems object parameter list, this is used to list the folders inside a file as choices.
Have you tried using a String parameter for it? I have several pipelines where I have paths defined as string parameters for use in shell scripts.
Are you sure Filesystem List Parameter can't be conigured to meet your needs?
I believe Extended Choice Parameter should allow you to do this. You'd have write as custom groovy, which could be tricky or take time to load.
You could maybe (request) enhance the Filesystem List Parameter plugin
Job A uses "For every property file, invoke one build" parameter factory to call downstream job B.
Here is the file pattern I am using:
d:\temp*.properties
There are two files in that folder:
build0.properties
build1.properties
each file looks something like this:
modified=SampleApp
Job B fails because job A is not setting the parameters from above file. If I look at the parameters for a build of Job B, they are empty.
The process works when I use "Parameters from properties file" parameter type instead of a parameter factory, and specify the full path to one of the files, so I know the files are in the right format. I do not want to add a parameter for each file I have,
since I will have these files generated dynamically.I would prefer to use the parameter factory if possible.
Issue with the file permissions, when I pointed to workspace directory with the file pattern It started workign fine.
Maybe I am misunderstanding the intended use for the Jenkins file parameter here...
I want to be able to upload a file containing some data (in my case comma separated variables). I then want to simply read this file and do stuff with the data. I've got this setup using a Pipeline job.
My file location is set to 'email_list.csv'. In my pipeline script I have
node {
stage('post') {
emailFile = readFile 'email_list.csv'
println "${emailFile}"
//.........
}
}
This fails with a java.io.FileNotFoundException: /var/lib/jenkins/workspace/job-name/email_list.csv (No such file or directory) exception
Shouldn't the parameterized build have set up this file? If not, how do I read the data uploaded?
Jenkins by default provides build job parameters as a params map in pipeline. It is a key-value pair. All you comma seperated values will be into values field. You can refer them in your groovy script as,
print params.emailFile
To dump it as a file, you can use writeFile library function.
P.S: If you print params in groovy script, you will be able to see all build parameters of your job.
There is a a bug since ages that makes impossible to use fileParameter:
Handle file parameters
file parameter not working in pipeline job
I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.
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.