Reputation: 338
My jenkins is located at myjenkins:8080/
After I run my Job it generates one file and I would like to get the complete path of it to give it to the user.
Example:
myjenkins:8080/job/FUTURE/job/GetFullPath/2/execution/node/3/ws/
I want to give this path to the user and the user would see the file generated there.
pipeline {
agent { label env.Machine}
stages {
stage('PREPARE'){
steps{
script{
env.custom_stage_name = "PREPARE"
bat '%FOLDER%\\CreateFile.bat'
}
}
}
stage('BUILD'){
steps{
ws("c:\\jenkins\\workspace\\Test") {
bat 'xcopy ' + '%FOLDER%\\File.txt ' + "c:\\jenkins\\workspace\\Test /I /s /e /h /y"
}
}
}
}
}
Upvotes: 0
Views: 9011
Reputation: 1326
Based on your title it's not clear to me if you just need a way to get the current working directory or you want to expose the directory so you can access it using a browser.
If you meant the second case: First at all, I think this is not possible without using a workaround. And there are some problems you need to work around!
First of all let me show you how to get the path to the workspace (if it is no obvious)
You can get the Path to your workspace by using the variable ${env.WORKSPACE}
Example:
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo "${env.WORKSPACE}"
}
}
}
}
Concatenate the file:
def my_file = "${env.WORKSPACE}/my.file"
To your actual problem
Unless your filename differs every run, it will get overwritten. There is no guarantee that the file in your workspace folder is preserved. To keep it you should tell Jenkins to archive (see point 2) your artifacts.
I can't image any good reason to expose your workspace like you want to do. So, let me give you some alternative first examples:
If you really want to expose the workspace using an URL
This involves a separate webserver, since I can't think of a way on how to tell Jenkins to expose it's working directories as a webservice.
If you just want to gain access to your workspace folder, you can expose it using a separate webserver. The ideas is to run a very simple web-server to serve the current workspace directory.
Here is one example on how to deploy exactly this using python.
Upvotes: 2