How can I explore Jenkins workspace? - jenkins

I want to scan file stored in my Jenkins project workspace.
for example, when I make a project named my_project, I will get report pattern from Jenkins like **/report.xml. and to find report.xml file, I will explore in my own plugin.
since when I print pwd on jenkins console, it prints where my plugin written, not jenkins workspace. so I need to know how to explore jenkins workspace in my plugin.
thanks!

If you're asking where your jenkins workspace is, it is in the workspace folder where you can find all your projects. It should be relative to your plugin folder: ../workspace. You can try to change directory using the relative path. Hope this helps.

Related

How to get build workspace path using jenkins remote api?

Is it possible to get current build's workspace path using jenkins remote api? I can get a build details based on build number with api/json, but it doesn't return the workspace details.
curl http://jenkinsServer:8080/job/testing/1/api/json
As far as I know you can't do that using Jenkins remote API. However, you can probably infer the workspace from your project name. If, say, Jenkins base workspace is /var/lib/jenkins/workspace (which is the case with default install on Unix), the workspace for your project should simply be :
/var/lib/jenkins/workspace/your-project
That could be sufficient for your needs, but workspace may vary, in particular if you are checking out some other repo inside your pipeline (or loading some other pipeline script from your base script), you could notice folders such as :
/var/lib/jenkins/workspace/your-project#tmp
/var/lib/jenkins/workspace/your-project#script

Where are Jenkins artifacts located?

I added the Archive Artifacts post-build option to my project. I can see the artifacts from the web browser interface, but I cannot find them in the filesystem.
Where are they located?
It is being archived on the master server (even if the build were on a slave) in the following folder:
$JENKINS_HOME/jobs/<job>/builds/<build>/archive
But you can configure a different location using the 'Advanced' setting of the job (where you can set a different workspace folder) or using plugins that are made for this purpose such as Copy Artifact Plugin
Just another couple of tips...
You can find jenkins home by going to the environment variables page in the job build jenkins page.
In my case JENKINS_HOME turned out to be /var/lib/jenkins
Found artifacts in:
/var/lib/jenkins/jobs/<my-job-name>-build/lastStable/archive/target
/var/lib/jenkins/jobs/<my-job-name>-build/lastSsuccessful/archive/target
as well as
/var/lib/jenkins/jobs/<my-job-name>-build/builds/8/archive/target
Path is : $JENKINS_HOME/jobs//jobs//branches//builds/$BUILD_NUMBER/archive/
You have to extract branch name, job name and repository name from JOB_NAME environment variable.

Jenkins slaves workspaces

I have a Jenkins multi-configuration project that I want to build on two slaves (Slave-1 and Slave-2) which are located on two different VM's. I am having a problem with how Jenkins attempts to create different workspaces for each slave. I want to use the same workspace path on each VM.
I am getting my project files from Perforce and want to put them in the directory c:\workspace on both VM's. However when I run a build, I look on the VM that has Slave-1 and it stores the project files under:
c:\workspace\label\Slave-1
On the other VM the project files is under:
c:\workspace\label\Slave-2
The folder 'label' under c:\workspace was the slave name I input for the configuration matrix.
How do I override Jenkins to put my project files under c:\workspace on each VM (without the \label\Slave_name folders)? I understand Jenkins does this to avoid confusion but my workspaces are on completely different VM's that won't interact with each other in any way. I have to use the c:\workspace directory in order to build properly.
You can start Jenkins with extra params:
-Dhudson.model.Slave.workspaceRoot=c:\workspace
Taken from here:
https://issues.jenkins-ci.org/browse/JENKINS-12667
Terms:
UnifiedDir: the target dir that you want to use that is the same on both VMs
Workspace: the dir that Jenkins creates that is unique to each VM
To get around the workspace isolation and unique naming, your build script should copy the entire workspace (or what you need from it) into the target unified directory. Then a Second call in your "Workspace\Build SCript" should call the "UnifiedDir\Build Script"
Now you have a unified workspace between build nodes. Just make sure you nuke the contents of this UnifiedDir BEFORE you copy the WORKSPACE contents over.

Publishing to Artifactory using Jenkins

I am trying to use the Generic Jenkins-Artifactory plugin to deploy the contents of the Jenkins build workspace into Artifactory. This seems to be somewhat fine using the following wildcards
Web\*.msi=>Testing\Web
Web\DeploymentSettings\*.xml=>Testing\Web\DeploymentSettings
Database\Scripts\**=>Testing\Database
However, when it comes to moving the contents of 'Database\Scripts' from the Jenkins workspace, empty folders under 'Database\Scripts' do not get copied into Artifactory. Non-empty folders however are copied successfully. It is important that I maintain the directory integrity/structure so it's a must that I copy these across.
I have considered placing empty text files in the empty directories to have them copy over successfully but I don't want to "pollute" the package.
Please help :-)
Thanks!
Looks like there is no workaround -other than dummy files in the directories.
I see some bugs in Jenkins releated to handling empty directories.
JENKINS-7260 Clone workspace doesn't copy empty directories when cloning entire workspace
JENKINS-20654Empty folders are not copied to the slave
Could you check if answer posted in Hudson: Copy artifact from master to slave fails helps?

Run Ant tast from Jenkins on Perforce

I'm trying to integrate Jenkins with Perforce, but I'm having a few problems.
I managed (apparently, because Jenkins still shows a "Unable to check workspace against depot" message) to link Jenkins to Perforce.
My project includes an Ant script to make the build and I cannot figure out how to use it.
I've added an Ant build step, indicating the name of the ant file (dev_build.xml), but when I run the job Jenkins complains that it cannot find the Ant file.
Jenkins looks for the file in its workspace, but the file is actually located in Perforce's workspace. I expected Jenkins to check out the project but this is not happening: the folder Jenkins\Workspace\MyProject is empty.
I've then copied the Ant file into Jenkins workspace folder, but obviously the Ant fails because it cannot find the source folder.
Any ideas?
I had to create a new perforce workspace dedicated to Jenkins, mapped to the workspace folder.
P4 now synchronizes the files correctly.

Resources