简体   繁体   English

Jenkins如何通过用户名和密码凭证进行结帐提取操作

[英]How Jenkins is passing username and password credentials for checkout pull operations

I have Jenkins / Mercurial latest versions. 我有Jenkins / Mercurial最新版本。 Machine is Red Hat Linux 6.6. 机器是Red Hat Linux 6.6。

I'm using Release plugin in Jenkins. 我在Jenkins中使用Release插件。 Maven plugins (maven-scm-plugin, maven-version-plugin and maven-enforcer-plugin) for doing release process on a project. 用于在项目上进行发布过程的Maven插件(maven-scm-plugin,maven-version-plugin和maven-enforcer-plugin)。 All of these versions are using latest available versions and configuration is setup correctly. 所有这些版本都使用最新的可用版本,并且配置正确。

In Jenkins job, I'm checking out the source code from a Project which sits behind RhodeCode (Mercurial hg). 在詹金斯(Jenkins)的工作中,我正在从位于RhodeCode(Mercurial hg)后面的项目中检查源代码。 在此处输入图片说明

Output shows like: 输出显示如下:

06:00:02 Started by timer
06:00:02 [EnvInject] - Loading node environment variables.
06:00:03 Building on master in workspace /main/jenkins/instance2/workspace/MyCoolProject
06:00:06 [MyCoolProject] $ hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" showconfig paths.default
06:00:06 [MyCoolProject] $ hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" pull --rev default
06:00:12 pulling from http://mercurialserver.my.company.com:9001/csa/MyCoolProject/
06:00:12 no changes found
06:00:12 [MyCoolProject] $ hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" update --clean --rev default
06:00:13 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
06:00:13 [MyCoolProject] $ hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" --config extensions.purge= clean --all
06:00:13 [MyCoolProject] $ hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" log --rev . --template {node}
06:00:13 [MyCoolProject] $ hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" log --rev . --template {rev}
06:00:13 [MyCoolProject] $ hg --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" log --rev 

As you see above, because we specified a user to perform the read/checkout operation in Mercurial DVCS tool, Jenkins passed bunch of parameters while initiating the hg commands ie 如上所示,由于我们指定了用户在Mercurial DVCS工具中执行读取/签出操作,因此Jenkins在启动hg命令时传递了一堆参数,例如

--config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" --config auth.jenkins.prefix = * --config ******** --config ******** --config“ auth.jenkins.schemes = http https”

I'm trying to find out how I can send the same, when I'm using Maven SCM plugin and it's goals. 当我使用Maven SCM插件及其目标时,我试图找出发送方法。

scm:checkin scm:签到
scm:tag scm:标签
etc which when called, initiates the underlaying version control commands (in my case, hg branch, hg outgoing, hg push commands). 等等,它们在被调用时会启动底层版本控制命令(在我的情况下,是hg分支,hg传出,hg推送命令)。

Right now, the above hg commands are failing due to the fact that either the user doesn't have ~/.hgrc file containing username and password variable set OR the user does NOT have "WRITE" access to the target RhodeCode/Mercurial repository. 目前,上述hg命令失败,原因用户没有〜/ .hgrc文件,其中包含用户名密码变量集, 或者用户没有“写”访问目标RhodeCode / Mercurial存储库的权限。

20:16:26 [INFO] --- maven-scm-plugin:1.9.4:checkin (default-cli) @ MyCoolProject ---
20:16:27 [INFO] EXECUTING: /bin/sh -c cd /main/jenkins/instance2/workspace/MyCoolProject && hg branch
20:16:27 [INFO] EXECUTING: /bin/sh -c cd /main/jenkins/instance2/workspace/MyCoolProject && hg outgoing
20:16:29 [INFO] EXECUTING: /bin/sh -c cd /main/jenkins/instance2/workspace/MyCoolProject && hg status
20:16:29 [INFO] [pom.xml:modified]
20:16:29 [INFO] [jenkins-MyCoolProject-43.appVersion.txt:unknown]
20:16:29 [INFO] [pom.xml.versionsBackup:unknown]
20:16:29 [INFO] EXECUTING: /bin/sh -c cd /main/jenkins/instance2/workspace/MyCoolProject && hg commit --message '"CM Jenkins - Release plugin auto check-in and creation of release tag = 0.0.29'
20:16:30 [INFO] EXECUTING: /bin/sh -c cd /main/jenkins/instance2/workspace/MyCoolProject && hg push http://cmprod2merc.my.company.com:9001/csa/MyCoolProject
20:16:34 [ERROR] 
20:16:34 EXECUTION FAILED
20:16:34   Execution of cmd : push failed with exit code: 255.
20:16:34   Working directory was: 
20:16:34     /main/jenkins/instance2/workspace/MyCoolProject
20:16:34   Your Hg installation seems to be valid and complete.
20:16:34     Hg version: 1.9.2 (OK)
  • I tried configuring ~/.hgrc file (as per Mercurial docs) and everything works if the username you specify in this file has valid WRITE access on the target source code repository/project then the above errors message won't come. 我尝试配置〜/ .hgrc文件(根据Mercurial docs),如果您在此文件中指定的用户名对目标源代码存储库/项目具有有效的WRITE访问权限,则一切正常,那么上述错误消息将不会出现。

  • This can also be resolved if I install/configure keyring and mercurial_keyring extension/plugin on the build machine (which is easy as per the online mercurial keyring documentation). 如果我在构建机器上安装/配置密钥环和mercurial_keyring扩展/插件,也可以解决此问题(根据在线mercurial密钥环文档,这很容易)。

What I'm trying to find out is : 我想找出的是
How can I pass the --config xxxxx parameters (like Jenkins is passing while doing checkout / pull operations - coming due to the setting values we have entered under Source Code Management in Jenkins job) to the hg commands which are called when Maven SCM plugin is initiating scm:checkin / scm:tag goals which ends up calling hg commands (hg outgoing , hg push ) / all hg commands without setting ~/.hgrc and installing mercurial_keyring? 我如何将--config xxxxx参数(例如Jenkins在执行结帐/提取操作时正在传递-由于我们在Jenkins作业的“ 源代码管理”下输入的设置值而来)传递给在Maven SCM插件中调用的hg命令正在发起SCM:签入 / SCM:标签的目标,其结束调用汞柱命令(HG 传出 ,HG 推送 )/所有hg的命令,而设定〜/ .hgrc和安装mercurial_keyring?

Found the solution: 找到了解决方案:

  1. Even when the user (jenkins) had valid WRITE access on the target RhodeCode/Merurial repository and either ~/.hgrc or mercurial_keyring setup wsa configured successfully (ie username/password less hg operations after one time manual entry), Maven SCM plugin scm:checkin and scm:tag operation were still failing. 即使用户(jenkins)在目标RhodeCode / Merurial存储库上具有有效的WRITE访问权限,并且成功配置了〜/ .hgrc或mercurial_keyring设置(即,在手动输入一次后,用户名/密码少了hg操作),Maven SCM插件scm: checkin和scm:tag操作仍然失败。

The reason for that is scm:checkin / scm:tag goals (of Maven SCM plugin) calls the version tool commands (hg commands in my case) but it was NOT passing the authentication params (username/password). 原因是(Maven SCM插件的)scm:checkin / scm:tag目标调用了版本工具命令(在我的情况下是hg命令),但未传递身份验证参数(用户名/密码)。 For that either I could have added the and values in project pom.xml OR in ~/.m2/settings.xml withing maven-scm-plugin plugin's configuration ---OR (more secured way is to) create/use 2 new Jenkins global level variables (of password type) to create username/password variables and use / pass them to scm:checkin / scm:tag goals while calling these goals within Release plugin's configuration settings in Jenkins ie -Dusername=$username and -Dpassword=$password (as the values are coming from Jenkins, they will be masked automatically). 为此,我可以使用maven-scm-plugin插件的配置在项目pom.xml中添加和值,或者在〜/ .m2 / settings.xml中添加-和 (更安全的方法是)创建/使用2个新的Jenkins全局级别的变量(具有密码类型)以创建用户名/密码变量,并将其使用/传递给scm:checkin / scm:tag目标,同时在Jenkins的Release插件的配置设置中调用这些目标,即-Dusername = $ username和-Dpassword = $密码(由于这些值来自Jenkins,因此将被自动屏蔽)。

I went with the Jenkins route and create 2 password type global variables in Jenkins Global configuration under "Configure system" > Global parameters/passwords section and just passed them to scm:checkin/tag goals while calling them in Invoke Maven step (within Release plugin configuration in Jenkins). 我沿用了Jenkins路由,并在“配置系统”>“全局参数/密码”部分的“ Jenkins全局配置”中创建了2个密码类型的全局变量,然后将它们传递给scm:checkin / tag目标,同时在Invoke Maven步骤中调用它们(在Release插件中) Jenkins中的配置)。

I found, if you have ~/.hgrc set with just username in it, then Jenkins checkout /pull commands started to fail as Jenkins process stopped using the credentials what I was using to pull/clone the source code (it seems like it was giving preference to the ~/.hgrc username first as Jenkins job/process was running with jenkins user and because it didn't had a password variable/field set in ~/.hgrc, the pull/clone failed for some reason (it should have given preference to the user/credentials what we specify in the job's configuration itself). If I moved ~/.hgrc to ~/.hgrc-backup, then checkout/pull/clone worked in Jenkins worked fine (as it used the credentials what I mentioned in the Source Code Management section for Mercurial) BUT, it still failed during Maven SCM plugin not handling the under laying hg commands. 我发现,如果您在〜/ .hgrc中设置了仅用户名,则Jenkins checkout / pull命令开始失败,因为Jenkins进程停止使用我用来拉/克隆源代码的凭据(似乎是当Jenkins作业/进程正在使用jenkins用户运行时,优先使用〜/ .hgrc用户名,并且因为在〜/ .hgrc中未设置密码变量/字段,因此pull / clone由于某种原因而失败(它应该如果我将〜/ .hgrc移至〜/ .hgrc-backup,则Jenkins的checkout / pull / clone可以正常工作(因为它使用了凭据)我在“ Mercurial”的“源代码管理”部分提到的内容,但在Maven SCM插件未处理底层hg命令的过程中仍然失败。

PS : running "hg push" on the workspace was working successfully (standalone, at command line) but when Maven SCM plugin was calling these goals and the goals were calling the hg commands, it didn't work for some reason. PS :在工作区上运行“ hg push”已成功运行(独立运行,在命令行上),但是当Maven SCM插件调用这些目标并且目标正在调用hg命令时,由于某种原因,它不起作用。

Solution was: 解决方案是:

  1. pass -Dusername=$username -Dpassword=$password variable to scm:checkin/scm:tag goals 将-Dusername = $ username -Dpassword = $ password变量传递给scm:checkin / scm:tag目标

  2. Make sure ~/.hgrc had username / password variables set --OR mercurial_keyring set to work with the repository (without prompting for username and password). 确保〜/ .hgrc设置了用户名/密码变量--OR mercurial_keyring设置为可与存储库一起使用(不提示输入用户名和密码)。

  3. The reason, Maven SCM plugin goals .. which called hg commands didn't work was due to an issue with the plugin I guess. Maven SCM插件目标..调用hg命令不起作用的原因是由于我猜插件存在问题。 A work around is to call these goals with -D pushChanges=false and this way, the goals will not call the under laying version control push operation and thus it'll succeed. 解决方法是使用-D pushChanges = false调用这些目标,这样,目标将不会调用底层版本控制推送操作,因此它将成功。 Then you have to manually add another step in the "Release Plugin in Jenkins's configuration" as "Execute Shell / Execute Windows Batch command" way to run "hg push". 然后,您必须以“执行Shell /执行Windows批处理命令”方式在“释放詹金斯配置中的插件”中手动添加另一步骤,以运行“汞推”。 Then, it will work and in this case, you don't need to pass -Dusername and -Dpassword parameters to these goals. 然后,它将起作用,在这种情况下,您无需将-Dusername和-Dpassword参数传递给这些目标。

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

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