I need to store a .csv or .txt file and access it from the Jenkinsfile. I currently have couple of files which are in the credential storage (logins, passwords and so on) but this file just has to be stored on the Jenkins machine. I know I could upload it directly to the node but I would prefer doing it in the similar fashion as with the credentials (using web interface).
You can save the file in Managed Files through the web interface: Manage Jenkins > Managed files > Add a new Config.
Each file saved there will have an auto generated ID or you can set your own id, next you can use Config File Provider Plugin to access your files through Jenkins Pipeline using the file ID like this:
configFileProvider([configFile(fileId: 'maven-settings', targetLocation: '/path/to/file/in/workspace')]) {}
Related
I wanted to know whatever configuration we do for jenkins pipeline from the UI, where does it get stored. If I want to parse a file that contains all the info Provided for jenkins pipeline, which file should I look into and where is it stored?
All jobs' configs are stored in $JENKINS_HOME/jobs folder.
Take a look at config.xml file in required job's folder.
I have automated a build/deploy process in Azure Devops / TFS and would like to scrape a file or folder name as a variable from the source file path that is used for my build artifact.
For example, I might want to scrape the folder name of the folder at the build source path and store it for use in the build #, release #, etc.
I have gone through Microsoft's documentation and I believe the information I'm looking for might be associated with the following... but I can't seem to find the right location.
Release.Artifacts.{alias}.BuildURI #The URL for the build.
Azure pipelines example: vstfs://build-release/Build/130
GitHub example: https://github.com/fabrikam/asp
When I attempt to locate the folder name from the source, I have so far been unable to find it in code.
Sorry, it's not possible to get the source file & folder name/Artifact name from the environment variable.
As of now, you need to specify the Artifact alias name in order to access the artifact related information.
E.g, Release.Artifacts.{alias}.DefinitionName
General Artifact variables
Primary Artifact Variables
Using default variables, you can use the default variables in two ways - as parameters to tasks in a release pipeline or in your scripts. here
I've been asked to move some variable from a Groovy script out into a configuration file. I'm fine using something like :-
readFile('../xx-software.cfg').split('\n').each { fileName ->
sh "wget ${theURL}${fileName}"
}
However, even though I have added xx-software.cfg into the same directory as my Groovy script it does become available for use within that groovy script.
I hope this makes sense!?
How can I move my variables out into a config file to make it easier for the application support team to make future edits without changing the code?
There are a few approaches you could use.
Firstly, file format for the configuration and how to read the data into variables. You could use Java Properties format, YAML or JSON and these are all handled by the Pipeline Utility Steps plugin with steps here. You can read the file with these steps:
readProperties
readYaml
readJSON
Next problem, how to get the file available to your pipeline so it can be read from the workspace using these steps. Possibilities are:
In source control with your pipeline code. It can be fetched with the pipeline.
In a separate source control for configuration, your pipeline will need a step to fetch it.
Use the Jenkins Config File Provider plugin. It has a step to provide a config file managed in Jenkins.
Provide it as a Custom Tool zipped archive from a binary server like Artifactory. You can use custom tool definition pipeline steps to make this available to the pipeline.
The Config File Provider option might provide any easy way to have a file that can be updated, but there won't be any version control of it.
The shared library files in jenkins are loaded at the beginning of the job, where does it get stored? I am trying to access the dockerfile stored in the shared library, I need the path to give in the docker build command. Is there a way I can find out the place where the shared library files are loaded in jenkins?
If the shared library is loaded from SCM and your workspace path is jenkins/workspaces/jobName, then a copy is checked out to jenkins/workspaces/jobName#libs or similar (might be suffixed with a number if that path is occupied by another concurrent build).
However, there is another way, if I understand you correctly you wan't to retrieve a resource in this library? In that case you should use the libraryResource and writeFile steps. Like this:
writeFile file:'myFile.txt', text:libraryResource("path/to/myFile.txt")
I have a jenkins job that pulls source code from GitHub public repo. I need to pass some files such as instance-specific configuration files containing secrets to the job and merge with source code prior to running build because these files are obviously inappropriate to be put in public SCM. The Jenkins instance is a multi-tenanted shared service.
The config files don't change often so I don't want to implement using file parameter which forces user manually input the file on every run. Another reason file parameter doesn't work is some builds are triggered automatically by SCM.
I don't want to use Config File Provider Plugin either, because the plugin requires jenkins admin access but I want users with job-level privileges manage the files themselves.
Ideally the uploaded files are saved alongside with job config.xml instead of in workspace, because I would like to delete workspace after each build. I can write scripts to copy the files from job config folder to workspace.
Are there any solutions available? Thanks.
If the "special" files are being placed in a folder with say some access privileges to it, couldn't you either run a Pre-SCM-Buildstep to move the files with shell commands, or introduce a regular build step (i.e. after the SCM stuff and before the other build steps) that would also use shell commands to move files?