How to create folder and text file in Jenkins common location - jenkins

We would like to create a folder in Jenkins commons location, this folder should be accessible for all Jenkins Job and builds. We will be creating one text file for each build in this central location. Can someone please suggest in Jenkins where we can create this kind of folder. We don't want to created in our Jenkins build work space - this folder location should be outside of Jenkins build workspace.
How can we achieve this - it would be really appreciated if someone can help us on this.

We are facing the same requirements, and we realized it by using a path to the file server.
Here some examples of our code:
// create new project file
new File("//<PATH_TO_YOUR_FILE_SERVER>/JenkinsCommon/${JOB_NAME}.txt").createNewFile()
new File("//<PATH_TO_YOUR_FILE_SERVER>/JenkinsCommon/${JOB_NAME}.txt").write("${ContentOfYourVariable}")
// read content from project file
String ProjectFileContent = new File("//<PATH_TO_YOUR_FILE_SERVER>/JenkinsCommon/${JOB_NAME}.txt").text
Does this help you or is it necessary to create the folder directly on your master?

I think for this requirement someone developed the External Workspace Manager Plugin
=> This plugin provides an external workspace management system. It facilitates workspace share and reuse across multiple Jenkins jobs. It eliminates the need to copy, archive or move files.

Related

Where to find option to change workspace path location in Jenkins?

I have recently installed Jenkin autodeploy tool. But I want to change it's default workspace location path which is pointing to my installable directory(c:) but now I want to keep my all projects in other drive so for that need to change workspace location.
But in my jenkin portal I am not finding that option.
Can anyone suggest me where can I find that?
Please see screen shot as well.
See Here
Thanks
Vijay
This option was removed in 2.121:
Build Record Root Directory and Workspace Root Directory can no longer be configured through the UI as these options were generally unsafe to use while Jenkins was running. Instead, these locations can now be customized using system properties on startup. Existing changes to these options will be retained unless and until overridden at startup.
Further details under JENKINS-50164.
Under the new model, one sets the workspace root with the hudson.model.Slave.workspaceRoot system property, which can be set as follows:
-Dhudson.model.Slave.workspaceRoot=/whatever
The exact mechanism for setting a property like this varies by OS/platform, but many typical options are described here. The full list of available system properties is on the Jenkins Wiki.
Since I also couldn't find under Jenkins -> Manage Jenkins -> Configure System the Advanced option. Where you can add a different directory for Build Record Root Directory.
You can change this property directly in the config.xml in the root folder of your Jenkins.
Here you can update the property to what you need to.
I would recommend using the following structure,
/path_to_the_folder/${ITEM_FULLNAME}/builds
Because using ${ITEM_FULLNAME} in the path, will put the builds of every job into its own folder.

How to change the workspace location from a jenkins plugin?

In jenkins, how do I design a plugin to take user's input on where to create the workspace on the filesystem?
I came across WorkspaceLocator but not sure how to use it. An example would be great.
[edit]
I want to be able to do this from the plugin's code. As in, for a particular type of project, the workspace should be created in some hard coded location that is declared in the code.
You can change the workspace at Advance Project options -> Use custom workspace under your job configuration.

How to set working directory to current workspace?

I am using TFS 2010. In the build process template, I add a new workflow activity InvokeProcess to run a batch file. I need to set the working directory of this InvokeProcess to the workspace directory of the Build agent. Is there any way to do this?
Should be able to use workspace object. Just type workspace and intelisense will kick in. This is built in object that holds the path to the build workspace. Others available are sourcesdirectory and binariesdirectory. Spelling maybe wrong not in front of a pc
I follow this answer and get it resolved: https://stackoverflow.com/a/9564712/3918598
Basically, you will need to create a new local variable SourcesPath at the outter most scope and then consume it wherever you want. Do not name it SourcesDirectory because that name has already been used by some inner activities.

Jenkins won't download svn:externals directory

I've added an svn:externals to my project, and it works great locally via TortoiseSVN. When I use Jenkins to pull from the same repository, it's not showing anything about the externals in the console output.
I read some other questions on here and I made sure my SVN version number in Jenkins was set to (1.6 externals to file) and restarted Jenkins. The problem is still occurring. Any ideas of something else I could set, or something I could use for troubleshooting? Thanks.
Oh, and the external directory is in the same repository, so I don't think it's an authentication issue as it builds fine without a reference to the external files.
I fixed this issue by selecting higher SVN Version Number on Jenkins 2.222.1.
Here is the procedure:
Manage Jenkins -> Configure System -> Subversion Workspace Version
Select at least v1.6. (The default one was 1.4 for me)
I may have had a very uncommon structure, but here's what worked for me...
First of all, here's the directory structure:
--Parent
----folder1
------subfolder1
------svnexternalfolder
----svnexternalfolder
As you can see, I had my svn external folder in two different levels of the project structure, but the Jenkins project was pointing directly at "folder1".
When first configured, it would never pull the files for my svn external folder (whether it was a full checkout, or svn update). This was configured with the svnexternals at the parent level.
My next try was to remove the svn externals at the parent, then specify just the higher location on the parent, then the lower location on folder1. This gave an error since the child svn directory had the same name as the other one.
So I flip-flopped the order of creating the svn external locations and did the child first (on "folder1"), then did the higher one on parent. Once I did that, everything started working.
Hope this helps someone else.
If you're curious about why I configured the directory structure this way, this was a PhoneGap project. apparently cordova/phonegap projects create their directory structures like this, the common folder beneath the parent is the "www" which houses all html, javascript, etc files, then those are also used under the platforms/ios, or platforms/android folders (in my example, I just called it folder1).

Mirror a TFS folder to a shared folder

I have a folder in TFS that I want to publish to a shared folder on my local network (read only access). I would like that anytime a change (or new file) is checked in, the files will be automatically updated in the shared folder.
What is the easiest way to do this?
I'd set up an automated build, with the server workspace mapped to the folder you want to monitor. The only thing the build would need to do is call out to xcopy. You'll probably need to create a custom workflow to do this but that should be fairly easy (famous last words)

Resources