jenkins - 如何在 Jenkins 服务器上使用证书凭据?

标签 jenkins credentials

我已经在 J​​enkins 服务器上创建了 Certificate 类型的凭据。如何使用它来签名文件?
目的是使用 signcode 对 Windows 文件进行签名,并使用 jarsigner 对 jar 文件进行签名。
请注意:凭据是全局的,每个 Jenkins 节点都应该可用。我无权访问 Jenkins 奴隶,我无法手动将证书放入文件系统。

最佳答案

这是对 jar 文件进行签名的方法——我不确定如何配置签名代码。

如果您有 PKCS#12 keystore ,请从 Jenkins Dashboard/Manage Jenkins/Manage credentials/Jenkins/Global credentials/Add credentials 选择 Kind: Certificate 和 Id: my-signing -凭据(例如)。

如果您使用的是声明式 Jenkinsfile,则可以使用 withCredentials .

Jenkins 文件:

pipeline { 
    stages { 
        stage('Build') { 
            steps { 
                withCredentials([certificate(
                        credentialsId:    'my-signing-credentials', 
                        keystoreVariable: 'my.keystore',
                        aliasVariable:    'my.alias',
                        passwordVariable: 'my.password')]) {
                    withMaven {
                        sh 'mvn deploy'
                    }
                }
            }
        }
    }
}

如果您使用的是 Jenkins Maven 作业,请转至配置/构建环境/使用 secret 文本或文件/绑定(bind)/添加/证书并输入 keystore 变量 (my.keystore)、密码变量 (my.password) 和别名变量 (my.alias),然后从弹出菜单中选择您的签名凭证。

在您的 pom.xml 中引用这些相同的变量:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>sign</id>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <keystore>${my.keystore}</keystore>
                    <alias>${my.alias}</alias>
                    <storepass>${my.password}</storepass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

关于jenkins - 如何在 Jenkins 服务器上使用证书凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41102650/

相关文章:

jenkins - @NonCPS 在 Jenkins 管道脚本中的作用是什么

android - Jenkins 使用 Android Google API 构建失败

c++ - 凭证提供者使用场景 : CPUS_UNLOCK_WORKSTATION removed from Windows 10

java - Java中如何检查数据库凭据是否正确?

jenkins - 使用 Jenkins 部署的 Openshift 问题

jenkins - 使用 Jenkins 实现单元测试用例自动化

ios - Jenkins 构建中的未知断言失败

c# - 在模拟下调用时 CredWrite 返回 1312

mysql - 如何使用 powershell 保护 mysql 连接

git credential.helper=cache 永远不会忘记密码?