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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章