代码改变世界

Jenkins 中 cd 与 dir

2024-07-03 11:16  qgbo  阅读(30)  评论(0编辑  收藏  举报
Jenkins file 如下:
pipeline {
    agent {label 'master'}
    stages {
        stage ('tttt') {
            steps {
                sh "pwd"
                sh "mkdir aaa"
                dir('aaa') {
                  sh "pwd"
                }
                sh "pwd"
                sh """
cd aaa
pwd
"""
echo "----------------------------" sh "cd aaa" sh "pwd" } } } }

   

dir 只改变wrap 内的路径,退出wrap,路径恢复到原来的地方

cd 命令根本不起效!


Running on Jenkins in /applications/jenkins/workspace/ssh_test [Pipeline] { [Pipeline] stage [Pipeline] { (tttt) [Pipeline] sh + pwd /applications/jenkins/workspace/ssh_test [Pipeline] sh + mkdir aaa [Pipeline] dir Running in /applications/jenkins/workspace/ssh_test/aaa [Pipeline] { [Pipeline] sh + pwd /applications/jenkins/workspace/ssh_test/aaa [Pipeline] } [Pipeline] // dir [Pipeline] sh + pwd /applications/jenkins/workspace/ssh_test
[Pipeline] echo
----------------------------
[Pipeline] sh
+ cd aaa
[Pipeline] sh
+ pwd
/applications/jenkins/workspace/ssh_test