我只能在 Ubuntu 上使用命令行终端。我需要使用安全凭证在 Jenkins 中创建工作。
我已经在我的机器上安装了 Jenkins,但是访问是开放的。如果我在 Jenkins 上设置安全凭证,我如何在命令行上指定这些?
我只能在 Ubuntu 上使用命令行终端。我需要使用安全凭证在 Jenkins 中创建工作。
我已经在我的机器上安装了 Jenkins,但是访问是开放的。如果我在 Jenkins 上设置安全凭证,我如何在命令行上指定这些?
跟着这些步骤:
从命令行为您要使用的用户生成一个公共 ssh 密钥:
ssh-keygen
每当您被要求输入一些值时,只需按 Enter 键。
复制文件的内容~/.ssh/id_rsa.pub
。
在浏览器中转到您的 jenkins 主屏幕并使用具有完全访问权限的用户登录,然后单击右侧的用户,然后单击您当前登录的用户。然后点击设置(或配置??)。
在SSH 公钥字段中粘贴id_rsa.pub
文件的内容。保存更改。
就这样!现在您可以从命令行使用 jenkins 了。
从命令行
以下是我的 jenkins 主用户(拥有所有权限)的配置文件。注意设置<authorizedKeys>
。您应该将公共 ssh 密钥粘贴到那里。我没有这样做,但如果你在配置文件中添加必要的行,它肯定会起作用。文件在/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>
我只是将启动提示位置更改为jar文件所在的文件夹。例如,如果您的 jar 文件的位置和名称是:
C:\Users\Tod\file.jar
你可以执行两个命令:
cd C:\Users\Tod
java -jar file.jar