Jenkins工作記錄

拷貝文件 xcopy

               script{
                    bat "xcopy LocalBuilds\\Engine\\Windows ${params.DeployDir}\\${params.branch} /y /e /i /q"
               }
  • 使用bat進行${params.xxx}參數傳遞時,需要使用script{}包裝

Git push

                dir("${params.DeployDir}")
                {
                    withCredentials([usernamePassword(credentialsId: 'git-pass-credentials-ID', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
                        bat """
                            git add .
                            git config --global user.email "${GIT_USERNAME}@xxx.com"
                            git config --global user.name "${GIT_USERNAME}"
                            git commit -m"[Jenkins] ${params.commitLog}"
                            git push https://${GIT_USERNAME}:${GIT_PASSWORD}@<REPO>
                        """
                    }
                }

  • 當git倉庫使用雙因素驗證時GIT_PASSWORD需設置爲personal access token
  • 使用https://${GIT_USERNAME}:${GIT_PASSWORD}@<REPO>時,如果賬號和密碼存在特殊字符需要轉義,如@->%40
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章