How to change the workspace location from a jenkins plugin? - jenkins

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.

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 create folder and text file in Jenkins common location

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.

Poll and checkout at different levels in SVN repository

We have a Visual Studio solution containing about a dozen class library projects. They're our team's main internal framework. In Jenkins we would like to automate the building of these projects as soon as a check-in is made, and also publish a new version to our local NuGet repo.
The problem: We would like to trigger the build by polling SVN at the class library level, e.g. ..trunk/OurSolution/OurCoreProject. Changes in one project should not trigger a build on all the other projects. But the checkout needs to be done one level higher, e.g. at ..trunk/OurSolution, and I cannot figure out how this can be done.
We've tried and contemplated a few solutions already:
Checking out at project level and then send the .csproj file to
MsBuild.exe instead of the .sln file. This fails because the project
expects a sibling folder named .nuget.
Looking into the Multiple SCMs
plugin, but it seems to mainly add the ability to use different SCM
providers in the same project(?) I would like to avoid adding this
plugin until I know it solves this.
Splitting all the projects up into separate solutions. Doesn't feel very optimal...
Is there a way to solve this in Jenkins? Have a missed any viable solution?
Yes you have missed something... the Advanced... button on the Subversion checkout configuration.
Do your SVN checkout on ..trunk/OurSolution
Click Advanced...
Under Included Regions, type ..trunk/OurSolution/OurCoreProject/*
For more info, click the ? icon next to relevant text area on the UI
If set, and Jenkins is set to poll for changes, Jenkins will ignore any files and/or folders that are not in this list when determining if a build needs to be triggered.

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 keeps changing my workspace path

I created a new project in Jenkins and when configuring made sure to uncheck the 'Let Jenkins Create Workspace' and 'Let Jenkins Manage Workspace View' boxes because I didn't want Jenkins to change my default workspace path (C:\workspace). However once a build was triggered it automatically changed the workspace path to C:\tools\Jenkins\jobs\project_name\workspace. Changing the path is unacceptable because a lot of my source files are dependent on the C:\workspace path.
Am I misunderstanding the function of the boxes I unchecked? How do I keep my path at C:\workspace?
I never used Perforce Plugin and I don't know what these checkboxes do. But normally if you want to fix workspace's path you can use Configure->Advanced Project Options->Use custom workspace checkbox. As described in documentation it does what you need:
Normally you should let Jenkins allocate and clean up workspace directories, but in several situations this is problematic, and in such case, this option lets you specify the workspace location manually.
One such situation is where paths are hard-coded and the code needs to be built on a specific location. While there's no doubt that such a build is not ideal, this option allows you to get going in such a situation.
Maybe you have to play also with 'Let Jenkins Create Workspace' and 'Let Jenkins Manage Workspace View' checkboxes.

Resources