仅在命令行中使用jenkins中的凭证创建作业 [英] Creating a job with credentials in jenkins only in command lines

查看:97
本文介绍了仅在命令行中使用jenkins中的凭证创建作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只允许在Ubuntu上使用命令行终端. 我需要使用安全凭证在Jenkins中创建工作.

I am only allowed to work with the command line terminal on Ubuntu. I need to create a job in Jenkins with security credentials.

我已经在计算机上安装了Jenkins,但是访问权限是打开的.如果我在Jenkins上设置了安全凭证,如何在命令行上指定这些凭证?

I already installed Jenkins in my machine, but the access is open. If I set up security credentials on Jenkins, how can I specify these on the command line?

谢谢!

推荐答案

按照以下步骤

  1. 通过命令行在您要使用的用户中生成公共ssh密钥.

  1. Generate a public ssh-key in the user you want to work with from the command line.

ssh-keygen

只要要求您输入一些值,只需按Enter键即可.

Just press enter whenever yo are asked to enter some value.

复制文件~/.ssh/id_rsa.pub的内容.

在浏览器中转到jenkins主屏幕,然后以具有完全访问权限的用户身份登录,然后在 Users 上单击右侧,然后在当前登录的用户上单击.然后点击设置(或配置?).

Go to your jenkins home screen in a browser and login with a user with full access, Then click on the right on Users and then on the user you are currently logged with. Then click on settings (or configuration??).

SSH公钥字段中粘贴id_rsa.pub文件的内容.保存更改.

In the field SSH public keys paste the content of the id_rsa.pub file. Save the changes.

仅此而已!现在,您可以从命令行使用jenkins.

And thats all! Now you are able to work with jenkins from the command line.

从命令行

以下是我的jenkins主要用户的配置文件(具有所有特权).注意设置<authorizedKeys>.您应该在此处粘贴公共ssh密钥.我还没有做到这一点,但是可以肯定的是,如果您将必要的行添加到您的配置文件中,它将起作用.该文件位于/path_to_jenkins/users/user_name/config.xml

The following is the configuration file of my jenkins main user (with all the privileges). Pay attention to the setting <authorizedKeys>. Yo should paste there the public ssh key. I haven't made that, but surely if you add the necessary lines to yor config file it works. The file is in /path_to_jenkins/users/user_name/config.xml

<?xml version='1.0' encoding='UTF-8'?>
<user>
 <fullName>admin</fullName>
 <description></description>
 <properties>
  <jenkins.security.ApiTokenProperty>
   <apiToken>pP08W9tzs2jlCrVCY9I2o6y2RNu3Huw85Y2f99/Uif7dia1W7piGpzsrpstln/jw</apiToken>
  </jenkins.security.ApiTokenProperty>
  <com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty plugin="credentials@1.4">
   <credentials/>
  </com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty>
  <hudson.tasks.Mailer_-UserProperty plugin="mailer@1.4">
   <emailAddress>admin@mail.com</emailAddress>
  </hudson.tasks.Mailer_-UserProperty>
  <hudson.model.MyViewsProperty>
   <primaryViewName></primaryViewName>
   <views>
    <hudson.model.AllView>
      <owner class="hudson.model.MyViewsProperty" reference="../../.."/>
      <name>Alle</name>
      <filterExecutors>false</filterExecutors>
      <filterQueue>false</filterQueue>
      <properties class="hudson.model.View$PropertyList"/>
    </hudson.model.AllView>
  </views>
</hudson.model.MyViewsProperty>
<hudson.security.HudsonPrivateSecurityRealm_-Details>
 <passwordHash>1DF2ykjkkkjkkQXW</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
<org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl>

<authorizedKeys>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4P1b/5RpibQgDZpKPD7lTQLjtyMrIQH43ns62PO72koL9zJe6qrAYcTIDNOUvSYNYyKfrgt6Z5zB8MvvENQLWezDKTWNXINhZml0PxOlc9ZaHbQX6UqyFbTS6o+ZEGs+K92Yi/XwK5hTmN5Igsw5BQYEs5cOsd5H2PoEZdhK1X0XAEBX/+p6aNy585+/scgZj0jSIvcX+pnzsCJLKmeYadlLnbrvebf9u6pu8MI9RuAY5dvPfpSL4WynWwS1QvY4z535TqPaaAlM3qXqH0pcOlxgW1iUkJqti3JnnxpBNXLmXalmq+4/d7mUrRBx+HKbh5ZpNZad9vaelAjAsNg+uw== user@machine_name</authorizedKeys>
</org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl>
  <hudson.search.UserSearchProperty>
   <insensitiveSearch>false</insensitiveSearch>
  </hudson.search.UserSearchProperty>
 </properties>
</user>

致谢.

这篇关于仅在命令行中使用jenkins中的凭证创建作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆