Jenkins Pipeline相对代码来创建拉取请求ib位桶

时间:2019-07-13 07:58:02

标签: jenkins jenkins-pipeline

我有Jenkins管道声明性代码,但出现错误。请检查以下管道声明性代码和帮助。 我在以下行上粘贴的错误。 我正在从事端到端自动化的构建,测试和部署。 我正在编写管道常规DSL代码来完成这项工作。涉及以下步骤。

1-检出Bitbucket分支

2-部署源代码

3-如果部署成功,我想提高Bitbucket的PR      源分支合并到master。

4-最后,当PR将合并时,最终部署将触发更高的      

 pipeline {      
   agent {label "dockercon2"}
   stages {                
        stage('checkout_stage'){
      steps {
         sh "id && whoami"
          checkout([$class: 'GitSCM', 
            branches: [[name: "*/${env.SOURCE_BRANCH}"]], 
              doGenerateSubmoduleConfigurations: false, 
                extensions: [[$class: 'CleanBeforeCheckout'], 
                  [$class: 'PerBuildTag'], 
                     [$class: 'IgnoreNotifyCommit'], 
                       [$class: 'PreBuildMerge', 
                          options: [mergeRemote: 'origin', mergeTarget: "${gitTargetbranch()}"]]], 
                            submoduleCfg: [], 
                               userRemoteConfigs: [[credentialsId: 'https_gitlab_clone_credential', name: 'origin', refspec: '+refs/heads/testing_pipeline:refs/remotes/origin/testing_pipeline', url: "${gitUrl()}"]]])
                    git branch: "${gitSourcebranch()}", credentialsId: 'https_gitlab_clone_credential', url: "${gitUrl()}"
                    withCredentials([usernamePassword(credentialsId: 'https_gitlab_clone_credential', passwordVariable: 'bb_pass', usernameVariable: 'bb_user')]){                        
                  sh "figlet 'wazzup'"
                  sh "figlet 'i am on'"
                  sh "git config credential.username ${UserName()}"
                  sh "git config credential.helper ${Gitlab_Pass()}" 
                  //sh "git config --global user.email ${UserEmail()}"
                  sh "git config --global user.name ${UserName()}"
                  //sh "set +x /bin/sh -c \"echo ${ansibleVaultCredentials()}>vault_passwd.txt\""
                  sh "set +x; echo ${ansibleVaultCredentials()} >> vault_passwd.txt"
                  sh "echo pass"
                  sh "cat vault_passwd.txt"
                  sh "ansible-vault decrypt --vault-password-file vault_passwd.txt test.sh && sh test.sh"   
               }// closing withCredential
        }// steps of checkout_stage

stage('creating_PR') {

   steps {
       when {
            step (currentBuild.result == "SUCCESS")  }

              triggers{
               bitbucketServer(bitbucketpr(projectPath: "${gitUrl()}",
                cron:'H/15 * * * *',
                credentialsId:'bitbucket_glone_cred',
                username:"${bb_user}",
                password:"${bb_pass}",
                repositoryOwner:'Atul',
                repositoryName:'valutstorage',
                branchesFilter:"${gitSourcebranch()}",
                branchesFilterBySCMIncludes:false,
                ciKey:'jenkins',
                ciName:'jenkins',
                ciSkipPhrases:'',
                checkDestinationCommit:false,
                approveIfSuccess:false,
                cancelOutdatedJobs:true,
                commentTrigger:''))
             }
         }
       }
     }
    } // Main stages block closer
   } // Pipeline closer


 ----------------Error i am getting ------------


 org.codehaus.groovy.control.MultipleCompilationErrorsException: 

 startup failed:

WorkflowScript: 49: Unknown stage section "stage". Starting with 

version 0.5, steps in a stage must be in a ‘steps’ block. @ line 49, 

column 5.

  stage('checkoutStage'){
   ^

1 error

at 

org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)

1 个答案:

答案 0 :(得分:0)

这可能是由于括号不匹配引起的。您没有正确关闭“ checkout_stage”块。在var temp = localStorage[filename.xml]; 之前添加一个右括号,然后删除最后一个右括号(“管道更近”)。那应该可以解决您的管道结构。

stage('creating_PR')