Fail Jenkins build when zero artifacts uploaded into artifactory - jenkins

I need my Jenkins build to fail in case zero artifacts are uploaded into the artifactory.
I have included failNoOp into my upload spec but it seems it's not working in my Jenkinsfile. Here is my code:
def server = Artifactory.newServer url: env.ArtifactoryServerTEST, credentialsId:'ArtifactoryUATServerKey'
server.bypassProxy = true
def uploadSpec = """{
"files": [
{
"pattern": "final_artifacts/*.gz",
"target": "test/"
}
]
}"""
server.upload spec: uploadSpec, failNoOp: true
This needs to fail my build if none of the artifacts are uploaded into the artifactory, but it is giving me this error:
java.lang.IllegalArgumentException: Only the following arguments are
allowed, [spec, buildInfo]
I'm using Artifactory OSS Version 6.2.0. anyone can help me on this?

As #yahavi mentioned, I could fix this problem by upgrade the artifactory plugin. I updated to the latest, so as at now current latest version is 3.3.2.

Related

Unsupported OS - I am trying to run Docker push Buildinfo in Windows machine but its get failed for Unsupported OS

node("DevHub && WinServer2019"){
cleanWs()
stage ("in windows docker") {
withDockerRegistry(credentialsId: "ABC_Technical_User", url: "https://abc-swc-build-toolchains-docker-dev") {
dockerImage = docker.image("abc-swc-build-toolchains-docker-dev/ci-snapshot/mt4/windows_vc100:image-13-77d3d3b")
dockerImage.pull()
String rtDocker = ''
def server = Artifactory.newServer url: 'https://abc/artifactory/', credentialsId: 'ABC_Technical_User'
def buildInfo = Artifactory.newBuildInfo()
// Step 2: Create an Artifactory Docker instance:
def bdDocker = Artifactory.docker server: server
buildInfo localBuildInfo = bdDocker.pull 'abc-swc-build-toolchains-docker-dev/ci-snapshot/mt4/windows_vc100:base-image-13-77d3d3b', 'abc-swc-build-toolchains-docker-dev'
// Step 4: Publish the build-info to Artifactory:
buildInfo.append localBuildInfo
echo "buildInfo : ${buildInfo}"
server.publishBuildInfo buildInfo
}
}
}
I am getting below error
INFO: Pulling image: abc-swc-build-toolchains-docker-dev/ci-snapshot/mt4/windows_vc100:base-image-13-77d3d3b
**java.lang.RuntimeException: Unsupported OS**
at com.github.dockerjava.netty.NettyDockerCmdExecFactory$UnixDomainSocketInitializer.init(NettyDockerCmdExecFactory.java:147)
at com.github.dockerjava.netty.NettyDockerCmdExecFactory.init(NettyDockerCmdExecFactory.java:116)
at com.github.dockerjava.core.DockerClientImpl.withDockerCmdExecFactory(DockerClientImpl.java:193)
at com.github.dockerjava.core.DockerClientBuilder.build(DockerClientBuilder.java:45)
at org.jfrog.build.extractor.docker.DockerJavaWrapper.getDockerClient(DockerJavaWrapper.java:77)
at org.jfrog.build.extractor.docker.DockerJavaWrapper.pullImage(DockerJavaWrapper.java:150)
at org.jfrog.build.extractor.docker.extractor.DockerPull.execute(DockerPull.java:76)
at org.jfrog.build.extractor.packageManager.PackageManagerExtractor.executeAndSaveBuildInfo(PackageManagerExtractor.java:33)
at org.jfrog.build.extractor.docker.extractor.DockerPull.main(DockerPull.java:61)
java.lang.RuntimeException: docker build failed
Can someone help me on this?
Would it be possible for you to test the scenario with the latest Jenkins Artifactory plugin and Java 11? I remember a similar issue reported in the past due to a lower Java version/old plugin as well. Upgrading the plugin to the latest version along with the respective Java version mentioned, should help in resolving the issue.

JFrog Artifactory artifacts uploaded via jenkins dont show up in builds

I use Jenkins to build my project, once that is done I upload the directory with all artifact files or just a single file to JFrog.
Pipeline-code example:
def server = Artifactory.server "jfrog1"
sh "touch uploadconfig.json"
writeFile(file: "uploadconfig.json", text: "{ \"files\": [ { \"pattern\": \"./uploadconfig.json\", \"target\": \"test-generic-local/uploadconfig1.json\", \"flat\" : \"true\" }]}")
uploadSpec = readFile 'uploadconfig.json'
uploadInfo = server.upload spec: uploadSpec
When the file is uploaded it has the build.name and build.number property.
But my issue is it will not show up under Artifactory -> Builds.
This is an issue since I want to have the option to download the latest file from this build using:
"files": [
{
"pattern": "test-generic-local/uploadconfig*",
"target": "./",
"build" : "nameOfMyJenkinsJob/LATEST"
}
]
When I try to run it now without the artifacts being listed under Build I get the following error message:
The build name nameOfMyJenkinsJob could not be found.
I see that you are not publishing the build to Artifactory. Kindly refer to this JFrog wiki on how to publish the build info. Also, I would recommend you referring this Github Jenkins file where in the build publish stage is where the build is pushed.

Jenkins pipeline script to publish into Jfrogartifactory

I am trying to write a pipeline script to publish *.war/*.jar file to JFrogArtifactory. I don't find any syntax for the same.
Anyone can help me out on the same.
please help me with a sample script.
JFrog has a dedicated GitHub repository with many examples for such cases.
There are Jenkins Pipelines examples there.
First, you must install Artifactory Plugin and config it in Jenkins server.
Refer: https://www.jfrog.com/confluence/display/JFROG/Configuring+Jenkins+Artifactory+Plug-in
And then try add below script to Jenkinsfile:
script {
def server = Artifactory.server '<artifactory id>'
def uploadSpec = '''{
"files": [{
"pattern": "<name of war or jar file>",
"target": "<artifactory repo>/path-to/war-or-jar/file/in-Artifactory"
}]
}'''
server.upload(uploadSpec)
}
Don't forget replace <artifactory id> <name of war or jar file> and <artifactory repo>/path-to/war-or-jar/file/in-Artifactory
More information: https://www.jfrog.com/confluence/display/JFROG/Declarative+Pipeline+Syntax
The scripted pipeline syntax for deploying war files to JFrog artifactory is :
env.ARTIFACTORY = 'True'
if(env.ARTIFACTORY == 'True')
{
stage('Deploying to Artifactory')
{
FAILED_STAGE = env.STAGE_NAME
bat 'mvn deploy'
}
}
Note :
1.) 'bat' command is for Windows batch file. If you're using Linux, replace 'bat' with 'sh'
2.) env.ARTIFACTORY is used to give you control over whether or not you want to execute this particular stage in your pipeline job. if you don't want this stage to execute, simply set env.ARTIFACTORY = 'False'
3.) Also note, you've to configure JFrog in : Manage Jenkins -> Configure system -> JFrog Platform Instances
4.) Include JFrog in your pom.xml file under distributionManagement tag.

How to specify version number when using Jenkins and Generic-Artifactory Integration?

I am able to integrate jenkins with artifactory to store my artifacts whenever a build is carried out, however whenever new artifacts are being pushed, the older versions will be removed automatically.
So I will like to check is there anyway for me to label each artifacts according to the version number or build number for easy version control.
Be sure to include the Jenkins ${env.BUILD_NUMBER} in the artifact path and name.
Assuming your Artifactory repository is set up as a Maven repository your pipeline should include something like this:
def uploadSpec = """{
"files": [
{
"pattern": "${env.PACKAGING_FOLDER}/${env.REPOSITORY_APPLICATION}-${env.BUILD_NUMBER}.zip",
"target": "${env.REPOSITORY_CODE}/${env.REPOSITORY_GROUP}/${env.REPOSITORY_APPLICATION}/${env.BUILD_NUMBER}/${env.REPOSITORY_APPLICATION}-${env.BUILD_NUMBER}.zip",
"regexp": "true"
}
]
}"""
def buildInfo = Artifactory.newBuildInfo()
buildInfo.env.capture = true
buildInfo = server.upload(uploadSpec)
server.publishBuildInfo(buildInfo)

Jenkins Pipeline - Upload to Artifactory: Failed to deploy file / Parent must be a folder

I have a Jenkins job which generate a zip file I want to updload to Artifactory. I have an issue setting the version of the artifact to be uploaded.
By convention, I use the timestamp has version. I want to upload file to my/group/timestamp/file.zip. The url of the file would be http://ArtifactoryAdress/foo/my/group/timestamp/file.zip
Here is my pipeline code
def serverArtifactory = Artifactory.server 'NameArtificatory'
def uploadSpec = """{
"files": [
{
"pattern": "file.zip",
"target": "my/group/${timestamp}/"
}
]
}"""
serverArtifactory.upload(uploadSpec)
I get the following error from Jenkins Job
java.lang.RuntimeException: java.io.IOException: Failed to deploy
file. Status code: 400 Response message: Artifactory returned the
following errors:
Parent my/group/timestampValue must be a folder Status code: 400
I looked around buildInfo but was not able to find how to set a version.
By the way, I am also agree with a solution without the timestamp but only group name.
Finally, this error is clear and simple.
As mentioned, a file with path my/group/timestampValue already exists. You have to delete it on Artifactory.
Don't forget it's still groovy use ${}. I used below code and it's work
def uploadSpec = """{
"files": [
{
"pattern": "**/target/*.war",
"target": "local-release/${APP_REPO}/${version.trim()}/${timestamp}.zip"
}
]}"""
server.upload(uploadSpec)
#Edit. And I just thought about it. Print please your ${timestamp}. Maybe it's contains characters with spaces, or something like this which Artifactory not allowed in directory name. Try trim your timestamp.trim()

Resources