publish over ftp jenkins plugin is not uploading subfolder - jenkins

I have a Jenkinsfile that deploys my angular app code to a site using the Publish over FTP plugin. All of the files in the dist folder are transferred except an assets subfolder. I have tried putting in the following values for the sourceFiles parameter with no success: 'webapp/dist/', 'webapp/dist/**', 'webapp/dist/**/*'.
Here is the publish over FTP part of my Jenkinsfile:
stage('Deploy') {
steps {
echo 'Deploying....'
ftpPublisher paramPublish: null, masterNodeName:'', alwaysPublishFromMaster: true, continueOnError: false, failOnError: true, publishers: [
[configName: 'Angular app', verbose: true, transfers: [
[asciiMode: false, cleanRemote: true, makeEmptyDirs:true, excludes: '', flatten: false,
noDefaultExcludes: false, patternSeparator: '[, ]+',
remoteDirectory: "webapp",
removePrefix: "webapp/dist",
remoteDirectorySDF: false,
sourceFiles: 'webapp/dist/**/*']
], usePromotionTimestamp: false, `enter code here`useWorkspaceInPromotion: false]
]
}
}
I've looked at the Publish over FTP pipeline documentation: https://jenkins.io/doc/pipeline/steps/publish-over-ftp/ and couldn't find anything parameters that I was missing. I'm stuck.

I was able to solve the issue. I changed the title of the pipeline to all lowercase letters without any spaces. I then changed the file path of the workspace folder to 'C:/jenkinsworkspace/${ITEM_FULL_NAME}' by modifying the workspaceDir entry in the config.xml located in the Jenkins root directory. I stopped the Jenkins service before modifying the config.xml. Both the assets folder and the favicon got generated in the build. It was one of the solutions mentioned in https://github.com/angular/angular-cli/issues/9230. Thanks for your help #Alberto L. Bonfiglio.

Related

JenkinsFile. sshPublisherDesc property

I attempting understand meaning sshPublisherDesc property from jenkins ssh publish plugin. Does anybody know what is it?
I checked docs (https://jenkins.io/doc/pipeline/steps/publish-over-ssh/) but they don't containt any description about that. Could anyone to explain it for me a bit?
ps. All examples of using this plugin contain this property but i can't image what is it.
It's the descriptor of each publisher, the api gives you this way to combine configName, transfers ...
https://github.com/jenkinsci/publish-over-ssh-plugin/blob/f75ee1db7a52f3cfddd138aae5149e02a4fc8258/src/main/java/jenkins/plugins/publish_over_ssh/descriptor/BapSshPublisherDescriptor.java
As I know this is ssh connection name for remote server
You will config it in the below image
Step 1:
Step 2: Add 2 sections
Step 3: Run Jenkins scripts with the above configuration
script {
sshPublisher(publishers: [sshPublisherDesc(configName: '10.90.9.11', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand:
'''
sudo docker stop, start command.......
''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'tmp')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
Hope to help you!

Warning: Identity file D:WorkKeyPairsDeployTech-O-Dex-APII not accessible: No such file or directory

I'm painfully new to Jenkins so I'm sorry for the silly question. I'm trying to get my jenkins to publish my .jar via SSH using the following:
sshPublisher(publishers: [sshPublisherDesc(configName: 'Tech-O-Dex-API', transfers: [sshTransfer(excludes: '', execCommand: 'ssh -i D:\\Work\\KeyPairs\\Deploy\\Tech-O-Dex-APII -n -f ec2-user#ec2-<IP>.compute-1.amazonaws.com "sh -c \'cd ~/; java -jar Tech-O-Dex-0.1.0.jar /dev/null &\\\'"', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: ' \'target/*.jar\'')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
however, I'm getting the following error:
Warning: Identity file D:WorkKeyPairsDeployTech-O-Dex-API not
accessible: No such file or directory.
I've tried specifying the key file, pem and ppk, nothing works? The file exists becasue I can use
scp -i D:\Work\KeyPairs\Tech-O-Dex-API D:\Jenkins\workspace\Tech-O-Dex\target\Tech-O-Dex-0.1.0.jar ec2-user#ec2-<IP>.compute-1.amazonaws.com:~/
inf the cmd line and it works fine to my EC2?
I'm on a windows machine which I'm almost positive is what is causing all of these headaches haha. Any help would be appreciated. Thanks
sources tried reference: Can't ssh to AWS EC2: Identity file not accessible

How to use publish over ssh plugin in pipeline

I would like to SSH to linux server from Jenkins hosted on windows and execute a command over in linux machine, I tried installing publish over ssh plugin and tested the connection in global config and it works fine, I don't know how to proceed next in pipeline. Any help would be appreciated.
If you are using a pipeline project and a Jenkinsfile, then all you need to do is go into your project in Jenkins and click configure. In the pipeline section of the configuration, at the bottom there is a link "pipeline syntax". It will take you to the Snippet Generator. Its self explanatory and in our case it allows to generate "publish over ssh" snippets that you would add to your Jenkinsfile (add it to a steps section inside a stage definition). In the generator you can define what to publish, options to run a shell command, etc. source
In case you were looking for the syntax for a declarative pipeline (Jenkinsfile) for Publish-Over-SSH, (Instead of the scripted pipeline, which is all I could find). Here's what finally worked for me.
pipeline{
agent any
environment {
RELEASENAME="yourProject-ci"
}
stages{
stage("Get the charts..."){
steps {checkout scm}
}
stage('SSH transfer') {
steps([$class: 'BapSshPromotionPublisherPlugin']) {
sshPublisher(
continueOnError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "kubernetes_master",
verbose: true,
transfers: [
sshTransfer(execCommand: "/bin/rm -rf /opt/deploy/helm"),
sshTransfer(sourceFiles: "helm/**",)
]
)
]
)
}
}
stage('Deploy Helm Scripts'){
steps([$class: 'BapSshPromotionPublisherPlugin']) {
sshPublisher(
continueOnError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "kubernetes_master",
verbose: true,
transfers: [
sshTransfer(execCommand: "cd /opt/deploy/helm;helm upgrade ${RELEASENAME} . --install"),
]
)
]
)
}
}
}
}
I have a checkout that happens first and then I copy some helm charts from the checkout to my kubernetes master and then run the charts.
configName: "kubernetes_master" is something I setup in the Publish_over_ssh plugin configuration section (Found under Manage Jenkins > Configure System) so I could reference it. It includes a username, sshkey, destination hostname, and base directory for the destination which I put as /opt/deploy.
FYI execCommand does not use the base directory... it assumes you will use full pathing.
Hope that helps.
edit: I should probably mention that there are lots more options for the sshPublisher than what I used. You can find them here: https://jenkins.io/doc/pipeline/steps/publish-over-ssh/
Based on levis answer, the below has worked for me.
stage('Deploy') {
agent any
steps {
sh 'mv target/my-app-0.0.1-SNAPSHOT.jar my-app.jar'
sshPublisher(
continueOnError: false,
failOnError: true,
publishers: [
sshPublisherDesc(
configName: "my-ssh-connection",
transfers: [sshTransfer(sourceFiles: 'my-app.jar')],
verbose: true
)
]
)
}
}
I got this question some time ago, and here is the answer. Change the code according to your requirement.
pipeline {
agent any
options { timestamps () }
stages {
stage('Publish over ssh plugin in pipeline') {
steps([$class: 'BapSshPromotionPublisherPlugin']) {
script {
List SERVERS_LIST = ["Server_1", "Server_2"]
for(cr_server in SERVERS_LIST){
sshPublisher(
publishers: [
sshPublisherDesc(
configName: cr_server,
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: '',
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: '**/*'
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: false
)
]
)
}
}
}
}
}
}
I don't know how helpful this'll be but I found a tutorial on something that should work until they have a nicer way to do it.

Declarative Jenkinsfile CIFS share

i have another question about the jenkins pipeline.
How can i publish the build artifacts to a windows share? In normal build jobs there is a "CIFS Publisher" post build action. But how can i use it in
post{
success {
//publish build artifacts
}
}
Is there any example?
I've succesfully managed it in this way:
cifsPublisher alwaysPublishFromMaster: false, continueOnError: false, failOnError: false, publishers: [[
configName: 'NAME_OF_THE_CIFS_CONFIG', transfers: [[
cleanRemote: false,
excludes: '',
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '$BUILD_NUMBER',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: 'myfile']],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true
]]
Please use the auto generate tool in Jenkins to help you.
As you can see the highlight link. Click it.
Fill all the required value that you expected.
After scroll down and click Generate pipeline script, you will see the syntax that you need.
Last step, copy the generated script into success clause.

Jenkins - HTML Publisher Plugin build fails with report directory doesnot exist

I am using the HTML publisher plugin and I am generating html report and placing in a report folder report/profile.html. I have specified the path where my report is in HTML directory to archive. I gave the path as /apps/cmjenkins/workspace/service_testapps_copy/LISA Project/Mezzo_Automation/Reports. That gave directory does not exist error so gave the complete path as well: C:/Users/dtiker/Documents/Feb24/universe1_0_testapps/service_testapps/LISA Project/Mezzo_Automation/Reports
Below is the error i see in console output after i run my jenkins build
12:45:34 [htmlpublisher] Archiving HTML reports...
12:45:34 [htmlpublisher] Archiving at PROJECT level C:/Users/dtiker/Documents/Feb24/universe1_0_testapps/service_testapps/LISA Project/Mezzo_Automation/Reports to /var/lib/jenkins/jobs/API_PROFILE_HTML_Report_POC/htmlreports/HTML_Report
12:45:34 ERROR: Specified HTML directory 'C:/Users/dtiker/Documents/Feb24/universe1_0_testapps/service_testapps/LISA Project/Mezzo_Automation/Reports' does not exist.
12:45:34 Build step 'Publish HTML reports' changed build result to FAILURE
12:45:34 Finished: FAILURE
I verified that that directory does exist. Can someone let me know what i am doing wrong?
Your job (each node{}) will use an own workspace, you should always reference files of the current build with a relative path!
publishHTML(reportDir: 'reports', reportFiles: 'profile.html'])
In my case misconfiguration of HTML publisher caused the problem
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
includes: '**/*.png', <--------------------- this line
keepAll: true,
reportDir: 'reports/',
reportFiles: 'friday_health_broker_portal_uat_index.html',
reportName: 'HTML Report',
reportTitles: 'FH BP'
])
Once I changed it includes to includes: '**/*' the problem was gone
when I used file path in "filepath " instead of 'filepath ', then its working fine for me
stage ('publish results') {
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: false,
reportDir: "/var/lib/jenkins/workspace/project/target/site/serenity",
reportFiles: "index.html",
reportName: 'HTML Report',
reportTitles: ''
])
}

Resources