你如何从Jenkins提供Artifactory凭据以供pip install使用。

huangapple go评论73阅读模式
英文:

How do you provide artifactory credentials from jenkins to pip install

问题

我有一个需要凭据才能从中下载/安装的Artifactory存储库。当我在本地命令行上运行pip install ...时,它会提示我输入凭据,我可以很好地输入我的Artifactory凭据。但我不知道如何在Jenkins上运行相同的脚本以向Artifactory提供这些凭据。

似乎Jenkins有一些插件用于管理凭据,例如https://jfrog.com/help/r/jfrog-integrations-documentation/configuring-jenkins-artifactory-plug-in?tocId=hB8yvLfVD7HRdvBLjM9adQ,但这些插件仅适用于流水线脚本本身,我不知道如何将它们传递给pip。

实际上,我有两个选择:(1)从Artifactory安装作为pip存储库,或者(2)通过git+ssh://...从git存储库安装。对我来说,如何从流水线脚本传递凭据给pip install命令都不清楚。

如何将Jenkins的ssh或Artifactory凭据传递给pip install

英文:

I've got an artifactory repository that requires credentials to download/install from. When I run pip install ... from the command line locally it prompts me for credentials, and I can type in my artifactory credentials just fine. I can't figure out how to run this same script on Jenkins to provide those credentials to artifactory.

It seems like Jenkins has a couple of plugins for managing credentials like https://jfrog.com/help/r/jfrog-integrations-documentation/configuring-jenkins-artifactory-plug-in?tocId=hB8yvLfVD7HRdvBLjM9adQ but these only work from the pipeline script itself, and I can't figure out how to thread this through to pip.

I realistically have two options: (1) install from artifactory as a pip repository, or (2) install from the git repo via git+ssh://.... Neither option is clear to me how to pass credentials from the pipeline script to the pip install command.

How do you pass either ssh or artifactory credentials from Jenkins to pip install?

答案1

得分: 1

根据pip文档,您可以在Jenkins凭据中使用用户名密码进行简单身份验证:

stage('示例') {
  environment { 
    PIP_CREDS = credentials('my-predefined-secret-text') 
  }
  steps {
    sh pip install https://$PIP_CREDS@pypi.company.com/simple
  }
}

如果您使用特殊字符,您可以使用.netrc文件与secretFile jenkins凭据,或者从$PIP_CREDS_USR $PIP_CREDS_PSW变量构建它,这些变量在用户名密码凭据中:

withCredentials([file(credentialsId: 'PIP_NETRC', variable: 'my-netrc')]){
  sh "cp $my-netrc /path/to/netrc/file/location" 
}

您还可以为pip设置.netrc路径,使用$my-netrc变量(查看pip文档)。

英文:

Based on pip docs you can use simple auth with username-password jenkins credentials :

stage('Example') {
  environment { 
    PIP_CREDS = credentials('my-predefined-secret-text') 
  }
  steps {
    sh pip install https://$PIP_CREDS@pypi.company.com/simple
  }
}

If you use special characters - you may use .netrc file with secretFile jenkins credentalsor build it from $PIP_CREDS_USR $PIP_CREDS_PSW variables in usernams-password credentals:

withCredentials([file(credentialsId: 'PIP_NETRC', variable: 'my-netrc')]){
  sh "cp $my-netrc /path/to/netrc/file/location" 
}

you may also set .netrc path with $my-netrc variable for pip(check pip docs)

huangapple
  • 本文由 发表于 2023年7月10日 22:47:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定