jenkins docker image create first admin user

已查看 238 次
跳至第一个未读帖子

Li Z

未读,
2017年8月29日 12:57:392017/8/29
收件人 Jenkins Users
I am trying to build a Jenkins docker image from jenkins/jenkins:2.67. Is there a way to create the first admin user with dockerfile? Thanks

Jacob Larsen

未读,
2017年8月29日 14:14:182017/8/29
收件人 jenkins...@googlegroups.com

Yes. Put this snippet into a .groovy file, e.g. usercreate.groovy:

    instance = Jenkins.getInstance()

    def hudsonRealm = new hudson.security.HudsonPrivateSecurityRealm(false)
    hudsonRealm.createAccount("admin","Password1234")
    instance.setSecurityRealm(hudsonRealm)
    def strategy = new hudson.security.GlobalMatrixAuthorizationStrategy()
    strategy.add(Jenkins.ADMINISTER, "admin")
    instance.setAuthorizationStrategy(strategy)
    instance.save()

Put the usercreate.groovy file next to your Dockerfile. Then add this line to your Dockerfile:

COPY usercreate.groovy /usr/share/jenkins/ref/init.groovy.d/

When Jenkins starts, a user with name "admin" will then be created with password "Password1234". Note the plaintext password, I'm not sure how to use a hash for this one.

This code will run every time Jenkins starts, so you may need to add a guard that checks if the admin user exists and only run the code if it does not exists.

/Jacob


On 2017-08-29 18:57, Li Z wrote:
I am trying to build a Jenkins docker image from jenkins/jenkins:2.67. Is there a way to create the first admin user with dockerfile? Thanks
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3927c485-df73-4fb0-82b0-70363846f432%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Li Z

未读,
2017年8月29日 17:26:122017/8/29
收件人 Jenkins Users
Thanks Jacob! It is exactly what I am looking for. 
回复全部
回复作者
转发
0 个新帖子