Skip to content

Commit

Permalink
Fix PyPi credentials (#38)
Browse files Browse the repository at this point in the history
* Fix PyPi credentials
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Nov 17, 2022
1 parent 75b24ef commit 6203a5a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
17 changes: 7 additions & 10 deletions tests/jenkins/TestPublishToPyPi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ import org.junit.Test
class TestPublishToPyPi extends BuildPipelineTest {

@Test
void setUp() {
void testWithDefaults() {
this.registerLibTester(new PublishToPyPiLibTester())
super.setUp()
super.testPipeline('tests/jenkins/jobs/PublishToPyPi_Jenkinsfile')
}

@Test
void 'verify default run'(){
runScript('tests/jenkins/jobs/PublishToPyPi_Jenkinsfile')

def twineCommands = getCommands('sh', 'twine')
assertThat(twineCommands, hasItem(
'twine upload -r pypi dist/*'
Expand All @@ -41,8 +35,10 @@ class TestPublishToPyPi extends BuildPipelineTest {
}

@Test
void 'verify custom dir'(){
runScript('tests/jenkins/jobs/PublishToPyPiWithDir_Jenkinsfile')
void testWithCustomDir() {
this.registerLibTester(new PublishToPyPiLibTester('test'))
super.setUp()
super.testPipeline('tests/jenkins/jobs/PublishToPyPiWithDir_Jenkinsfile')

def twineCommands = getCommands('sh', 'twine')
assertThat(twineCommands, hasItem(
Expand All @@ -53,8 +49,8 @@ class TestPublishToPyPi extends BuildPipelineTest {

def signing_sh = getCommands('sh', 'sign.sh')
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n /tmp/workspace/sign.sh test --sigtype=.asc --platform=linux\n '))

}

def getCommands(method, text) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == method
Expand All @@ -65,4 +61,5 @@ class TestPublishToPyPi extends BuildPipelineTest {
}
return shCommands
}

}
6 changes: 2 additions & 4 deletions tests/jenkins/jobs/PublishToPyPiWithDir_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
PublishToPyPiWithDir_Jenkinsfile.publishToPyPi({artifactsPath=test})
publishToPyPi.legacySCM(groovy.lang.Closure)
publishToPyPi.library({identifier=jenkins@main, retriever=null})
publishToPyPi.sh(echo args to test)
publishToPyPi.sh(echo release test)
publishToPyPi.signArtifacts({artifactPath=test, sigtype=.asc, platform=linux})
signArtifacts.echo(PGP or Windows Signature Signing)
signArtifacts.fileExists(/tmp/workspace/sign.sh)
Expand All @@ -29,6 +27,6 @@

/tmp/workspace/sign.sh test --sigtype=.asc --platform=linux
)
publishToPyPi.usernamePassword({credentialsId=jenkins-opensearch-pypi-username, usernameVariable=TWINE_USERNAME, passwordVariable=TWINE_PASSWORD})
publishToPyPi.usernamePassword({credentialsId=jenkins-opensearch-pypi-credentials, usernameVariable=TWINE_USERNAME, passwordVariable=TWINE_PASSWORD})
publishToPyPi.withCredentials([[TWINE_USERNAME, TWINE_PASSWORD]], groovy.lang.Closure)
publishToPyPi.sh(twine upload -r pypi test)
publishToPyPi.sh(twine upload -r pypi test/*)
2 changes: 1 addition & 1 deletion tests/jenkins/jobs/PublishToPyPi_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@

/tmp/workspace/sign.sh dist --sigtype=.asc --platform=linux
)
publishToPyPi.usernamePassword({credentialsId=jenkins-opensearch-pypi-username, usernameVariable=TWINE_USERNAME, passwordVariable=TWINE_PASSWORD})
publishToPyPi.usernamePassword({credentialsId=jenkins-opensearch-pypi-credentials, usernameVariable=TWINE_USERNAME, passwordVariable=TWINE_PASSWORD})
publishToPyPi.withCredentials([[TWINE_USERNAME, TWINE_PASSWORD]], groovy.lang.Closure)
publishToPyPi.sh(twine upload -r pypi dist/*)
2 changes: 1 addition & 1 deletion vars/publishToPyPi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void call(Map args = [:]) {
platform: 'linux'
)

withCredentials([usernamePassword(credentialsId: 'jenkins-opensearch-pypi-username', usernameVariable: 'TWINE_USERNAME', passwordVariable: 'TWINE_PASSWORD')]) {
withCredentials([usernamePassword(credentialsId: 'jenkins-opensearch-pypi-credentials', usernameVariable: 'TWINE_USERNAME', passwordVariable: 'TWINE_PASSWORD')]) {
sh """twine upload -r pypi ${releaseArtifactsDir}/*"""
}
}

0 comments on commit 6203a5a

Please sign in to comment.