groovy 如何使用httpRequest Jenkins插件上传nexus工件

uz75evzq  于 2022-11-01  发布在  Jenkins
关注(0)|答案(3)|浏览(328)

有没有办法用httpRequest Jenkins插件上传一个nexus工件。我确实试过用以下插件上传它:

String basicAuthString = "Basic " + "${user}:${password}".bytes.encodeBase64().toString()

String formBody = 'r=temp&g=org.codehaus.groovy&a=groovy-binary&v=2.3.7&p=zip&file=@groovy-binary.zip&hasPom=false'

def response = httpRequest contentType: 'APPLICATION_FORM', requestBody: formBody, consoleLogResponseBody: true, customHeaders: [[maskValue: false, name: 'Authorization', value: basicAuthString]], httpMode: 'POST', url: this.env.NEXUS_UPLOAD_URL

不幸的是,我收到以下错误

Response Code: HTTP/1.1 400 Bad Request
Response: 
<html><body><error>Deployment tried with both 'packaging' and/or 'extension' being empty! One of these values is mandatory!</error></body></html>`

我做错了什么吗?有可能使用这个插件吗?

jei2mxaa

jei2mxaa1#

目前还没有办法上传它与此插件只是因为nexus正在等待形式上传。当您上传文件与其他输入您需要使用
Content-Type: multipart/form-data .
在当前版本中,httpRequest插件没有这样的contentType

pgvzfuti

pgvzfuti2#

是的,这是可行的,用一个简单的“PUT”,至少当推到一个“原始”的回购协议

httpRequest authentication: 'auth_user', httpMode: 'PUT', requestBody: writeYaml(data: data, returnText: true), url "$(env.NEXUS_URL)/repository/upload_repo/test.yaml", wrapAsMultipart: false
sczxawaw

sczxawaw3#

您需要上传原始文件,即不包含任何多部分规范。下面是一个经过测试的工作示例,用于将“mycustompackage-1.0-0.rpm”发布到Nexus Yum存储库。您可以遵循Maven存储库的相同模式。

String authHeaderValue = 'Basic ' + 'myUserName:myPassword'.bytes.encodeBase64().toString()

def response = httpRequest  url: 'https://nexus.myorg.com/repository/my-yum-repo/rhel/8.5/os/x86_64/packages/mycustompackage-1.0-0.rpm',
                            customHeaders: [ [name: 'Authorization', value: authHeaderValue ] ],
                            httpMode: 'PUT',
                            uploadFile: '/tmp/mycustompackage-1.0-0.rpm',
                            wrapAsMultipart: false

assert response.status.equals(200) : "Upload FAILED !! Expected '200' HTTP response code (response code='${response.status}', response text=\n${response.content})"

相关问题