简体   繁体   English

Jenkins Pipeline Checkout SVN到自定义工作区

[英]Jenkins Pipeline Checkout SVN to custom workspace

I'm writing an Jenkins Pipeline script at the moment (declarative). 我现在正在写一个Jenkins Pipeline脚本(声明式)。 Basically like this: 基本上是这样的:

pipeline {
    agent any
    environment {
        NLS_LANG = 'GERMAN_GERMANY.AL32UTF8'
    }
    stages {
        stage('Test') {
            steps {
                script {
                    echo "Test"
                }
            }
        }
    }
}

The script itself works fine. 脚本本身可以正常工作。 But we now found out, that the jenkins checks out our SVN repository first to find the Jenkinsfile (Checkout in folder workspace@script in the job Folder > C:\\jenkins_home\\jobs\\<Projectname>\\jobs\\<Jobname> ). 但是现在我们发现,jenkins首先检出了SVN存储库以找到Jenkinsfile(在job Folder > C:\\jenkins_home\\jobs\\<Projectname>\\jobs\\<Jobname> >中的job Folder workspace@script @script文件夹中检出)。

Than the whole SVN is checked out again in an second step which I didn't wrote in the Jenkinsfile (Title: " Declarative: SCM Checkout "). 在第二步中,我再次没有检出整个SVN,我没有在Jenkinsfile中写过(标题:“ Declarative: SCM Checkout ”)。 It would be okay, if we could change the path of this checkout, because at the moment it checks out in a new created workspace folder in the job folder . 如果我们可以更改此签出的路径,那就可以了,因为目前,它在job folder夹中新创建的workspace文件夹中签出。

Here I have a screenshot from the console output of the pipeline job: 这里有管道作业的控制台输出的屏幕截图: 在此处输入图片说明

How can the checkout in a custom workspace be achieved? 如何实现自定义工作区中的结帐?

Preferably it would only checkout the Jenkinsfile on it's own on the first checkout, not the whole repository. 最好只在第一次签出时自己签出Jenkinsfile,而不是整个存储库。 I tried to change the repository url to the folder where the Jenkinsfile is saved (alone), but than the pipeline is also (only) checking out this folder on the second checkout. 我试图将repository url更改为(单独)保存Jenkinsfile的文件夹,但是管道也(仅)在第二次签出时签出了该文件夹。

Here I have a screenshot of the console output trying this: 在这里,我有尝试这样做的控制台输出的屏幕截图:

To whom it may concern when coming around this question: use a ws('/path/to/dir') to allocate a different directory (see Pipeline: Nodes and processes ) 遇到此问题时可能会向谁关注:使用ws('/ path / to / dir')分配其他目录(请参阅管道:节点和进程

pipeline {
    agent any
    environment {
        NLS_LANG = 'GERMAN_GERMANY.AL32UTF8'
    }
stages {
    stage('Test') {
        steps {
            script {
                echo "Test"
                ws('/path/to/dir'){
                    //dosomething here, like "checkout scm"
                }
            }
        }
    }
}    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM