Jenkinfile DSL how to specify target directory

后端 未结 5 1063
予麋鹿
予麋鹿 2021-02-18 14:17

I\'m exploring Jenkins 2.0 pipelines. So far my file is pretty simple.

node {
    stage \"checkout\"
    git([url:\"https://github.com/luxengine/math.git\"])

           


        
5条回答
  •  日久生厌
    2021-02-18 14:50

    Clarification

    Looks like you are trying to configure Pipeline job (formerly known as Workflow). This type of job is very distinct from Job DSL.

    The purpose of Pipeline job is to:

    Orchestrates long-running activities that can span multiple build slaves. Suitable for building pipelines (formerly known as workflows) and/or organizing complex activities that do not easily fit in free-style job type.

    Where as Job DSL:

    ...allows the programmatic creation of projects using a DSL. Pushing job creation into a script allows you to automate and standardize your Jenkins installation, unlike anything possible before.

    Solution

    If you want to checkout your code to specific directory then replace git step with more general SCM checkout step. Final Pipeline configuration should look like that:

    node {
        stage "checkout"
        //git([url:"https://github.com/luxengine/math.git"])
        checkout([$class: 'GitSCM', 
            branches: [[name: '*/master']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[$class: 'RelativeTargetDirectory', 
                relativeTargetDir: 'checkout-directory']], 
            submoduleCfg: [], 
            userRemoteConfigs: [[url: 'https://github.com/luxengine/math.git']]])
    
        stage "build"
        echo "Building from pipeline"
    }
    

    As a future reference for Jenkins 2.0 and Pipeline DSL please use built-in Snippet Generator or documentation.

提交回复
热议问题