How to change the current workspace in a pipeline script?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to change the current workspace in a pipeline script?

Sandra Parsick
Hello,

I'd like to change the current workspace in a pipeleine script. My naive approach is the following script

pipeline {
    agent any
    environment
{
        WORKSPACE
= '/home/sparsick'
   
}
    stages
{
        stage
('Build') {
            steps
{
                sh
'echo $WORKSPACE'
                sh
'pwd'
           
}
       
}
     
   
}
}

The output of this script:

Running on Jenkins in /home/sparsick/dev/jenkins-2.0/workspace/Workspace Change In Pipeline
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
[Workspace Change In Pipeline] Running shell script
+ echo /home/sparsick
/home/sparsick
[Pipeline] sh
[Workspace Change In Pipeline] Running shell script
+ pwd
/home/sparsick/dev/jenkins-2.0/workspace/Workspace Change In Pipeline
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

I expected that the output of the pwd command is the same as the output of the echo command. But It isn't. So my question how I can change the current workspace in a pipeline script?

Thank you and best regards,

Sandra

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/63b8f006-6db3-4c90-b547-afac04d83685%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to change the current workspace in a pipeline script?

Mark Waite-2


On Sun, Apr 8, 2018 at 4:00 AM 'Sandra Parsick' via Jenkins Users <[hidden email]> wrote:
Hello,

I'd like to change the current workspace in a pipeleine script.



Mark Waite
 
My naive approach is the following script

pipeline {
    agent any
    environment
{
        WORKSPACE
= '/home/sparsick'
   
}
    stages
{
        stage
('Build') {
            steps
{
                sh
'echo $WORKSPACE'
                sh
'pwd'
           
}
       
}
     
   
}
}

The output of this script:

Running on Jenkins in /home/sparsick/dev/jenkins-2.0/workspace/Workspace Change In Pipeline
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
[Workspace Change In Pipeline] Running shell script
+ echo /home/sparsick
/home/sparsick
[Pipeline] sh
[Workspace Change In Pipeline] Running shell script
+ pwd
/home/sparsick/dev/jenkins-2.0/workspace/Workspace Change In Pipeline
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

I expected that the output of the pwd command is the same as the output of the echo command. But It isn't. So my question how I can change the current workspace in a pipeline script?

Thank you and best regards,

Sandra

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/63b8f006-6db3-4c90-b547-afac04d83685%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtHCOs2rBr_WaEx7xwSR__Of-2b_d3A0KgDNSm6jbDUxrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to change the current workspace in a pipeline script?

Sandra Parsick
Thank you for help

Am Sonntag, 8. April 2018 16:09:48 UTC+2 schrieb Mark Waite:


On Sun, Apr 8, 2018 at 4:00 AM 'Sandra Parsick' via Jenkins Users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ngLxRz0aBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com> wrote:
Hello,

I'd like to change the current workspace in a pipeleine script.

See the ws() directive <a href="https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-ws-code-allocate-workspace" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fpipeline%2Fsteps%2Fworkflow-durable-task-step%2F%23code-ws-code-allocate-workspace\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFqgMsShZarR4YRltWop5UuEZc-0g&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fpipeline%2Fsteps%2Fworkflow-durable-task-step%2F%23code-ws-code-allocate-workspace\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFqgMsShZarR4YRltWop5UuEZc-0g&#39;;return true;">https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-ws-code-allocate-workspace 

See also <a href="https://stackoverflow.com/questions/43627358/how-to-set-specific-workspace-folder-for-jenkins-multibranch-pipeline-projects" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F43627358%2Fhow-to-set-specific-workspace-folder-for-jenkins-multibranch-pipeline-projects\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFNNSId4gzZIc7nWBkZXzHiGbfnAw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F43627358%2Fhow-to-set-specific-workspace-folder-for-jenkins-multibranch-pipeline-projects\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFNNSId4gzZIc7nWBkZXzHiGbfnAw&#39;;return true;">https://stackoverflow.com/questions/43627358/how-to-set-specific-workspace-folder-for-jenkins-multibranch-pipeline-projects and <a href="https://stackoverflow.com/questions/43577139/what-does-a-ws-block-do-in-jenkins" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F43577139%2Fwhat-does-a-ws-block-do-in-jenkins\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF2aiz3JxRAsHVdR5UGTfaUYOdEmw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F43577139%2Fwhat-does-a-ws-block-do-in-jenkins\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF2aiz3JxRAsHVdR5UGTfaUYOdEmw&#39;;return true;">https://stackoverflow.com/questions/43577139/what-does-a-ws-block-do-in-jenkins

Mark Waite
 
My naive approach is the following script

pipeline {
    agent any
    environment
{
        WORKSPACE
= '/home/sparsick'
   
}
    stages
{
        stage
('Build') {
            steps
{
                sh
'echo $WORKSPACE'
                sh
'pwd'
           
}
       
}
     
   
}
}

The output of this script:

Running on <a href="http://localhost:8001/computer/(master)/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flocalhost%3A8001%2Fcomputer%2F(master)%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHqbDI2vgdh60DXBqLFb2snuiUOig&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flocalhost%3A8001%2Fcomputer%2F(master)%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHqbDI2vgdh60DXBqLFb2snuiUOig&#39;;return true;">Jenkins in /home/sparsick/dev/jenkins-2.0/workspace/Workspace Change In Pipeline
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
[Workspace Change In Pipeline] Running shell script
+ echo /home/sparsick
/home/sparsick
[Pipeline] sh
[Workspace Change In Pipeline] Running shell script
+ pwd
/home/sparsick/dev/jenkins-2.0/workspace/Workspace Change In Pipeline
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

I expected that the output of the pwd command is the same as the output of the echo command. But It isn't. So my question how I can change the current workspace in a pipeline script?

Thank you and best regards,

Sandra

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ngLxRz0aBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/63b8f006-6db3-4c90-b547-afac04d83685%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/63b8f006-6db3-4c90-b547-afac04d83685%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/63b8f006-6db3-4c90-b547-afac04d83685%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/63b8f006-6db3-4c90-b547-afac04d83685%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/dd58069e-2794-43c7-a13c-7a09efe19eeb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.