Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cross-platform build pipeline examples. #54

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

BillHoo
Copy link

@BillHoo BillHoo commented Sep 22, 2016

I'm using Jenkins pipeline plugin for my cross-platform libraries build. But at the beginning, I find its hard to write a cross-platform pipeline script, there's no such a example in official site. So I made my own and wish it can help others.

I'm using Jenkins pipeline plugin for my cross-platform libraries build. But at the beginning, I find its hard to write a cross-platform pipeline script, there's no such a example in official site. So I made my own and wish it can help others.
I'm using Jenkins pipeline plugin for my cross-platform libraries build.
But at the beginning, I find its hard to write a pipeline script for cross-platform build, there's no such a example in official site. So I made my own and wish it can help others.
Copy link
Member

@orrc orrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the build, archive, and cleanup commands in separate blocks doesn't seem reliable — there may be multiple nodes with the same label, and I don't believe it's guaranteed that you'll always get the same workspace between the stages being executed.

// -- ios
// -- macos
// --symbols
// -- win32 (Dir to hold PDB symbols generate from CMake)
Copy link
Member

@orrc orrc Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, information like this should go into a README in the root of this directory.


// Stash all source files for another platform usage.
// NOTE: the stashed file's scope is in node 'master', so we can unstash it later.
stash name: 'YOUR_CROSSPLATFORM_SOURCES'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I don't think it's a good idea to stash the entire workspace — but in this case if your full checkout takes less than 10 seconds, it might be ok.

But after the initial checkout, I imagine it should be faster to allow each parallel branch to update its clone, rather than stashing and unstashing the entire workspace at the start of every build.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 'stash/unstash' topic:
In real uasge, I'm excluding much files than stashing whole worksapce, only source code was stashed, and Jenkins was setup on the same server which host my SVN, so checkout to a local workspace is fast enough for small and medium-sized project. And for this example, I removed 'exclude' session to simplify the syntax. Should we add 'exclude' back?

For 'checkout' topic:
This is a little complex, at the beginning, I'm following Jenkins guide to checkout(update clone after initial checkout) project on each platform, it works fine before I meet these two main problems:

  1. Checkout/Update on each OS made me copy at least four times(Linux/Win32/MacOS/iOS) of the same 'checkout' code in the Jenkinsfile, it doesn't smells good to me.
  2. According to the 1st reason, I'm wondering if there's any solution to avoid that copy, and I find that only 'stash/ubstash' works, but the drawback is the unstashed files is out of version control, so I need cleanup whole agent workspace after every build.

Currently the 'stash/unstash' solution works fine to me, but I'm still searching for a better one. Is there's any official examples or guidelines for cross-platform build pipleline template? Or I'll keep to make my branch better for general cross-platform usage. :)

"win32-stream" : {
node('win32') {
// This will copy all files packaged in YOUR_CROSSPLATFORM_SOURCES to agent workspace root directory.
// To copy to another agent directory, see [https://github.com/BillHoo/pipeline-examples/tree/master/pipeline-examples/unstash-different-dir]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL should point to https://github.com/jenkinsci/pipeline-examples

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, the URL was a mistake, I'll fix it later.

"win32-archiving" : {
node('win32') {
step([$class: 'ArtifactArchiver', artifacts: 'dist\\win32\\*', fingerprint: true])
step([$class: 'ArtifactArchiver', artifacts: 'symbols\\win32\\*', fingerprint: true])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This verbose syntax is no longer required; archiveArtifacts artifacts: '**/foo.bar', fingerprint: true should be sufficient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deal, this will be fixed later.

// Final cleanup
// Why we need this cleaup?
// stash/unstash command just copy files from source to dest without any version control stuff like Git/SVN did.
// So all files will stay in agent workspace if we dont't remove it, and may cause issues when we launch next build.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to above: I'd just use git clean (if using Git) :)

@BillHoo
Copy link
Author

BillHoo commented Sep 23, 2016

Hi @orrc , thanks for reviewing, I'm struggling to write a well-performed pipeline for my cross-platform library project, and I appreciate for any advises which can make it better.

Running the build, archive, and cleanup commands in separate blocks doesn't seem reliable — there may be multiple nodes with the same label, .

For this, I have three agent node named as 'win32' 'ios' and 'android', how could it be unreliable?

and I don't believe it's guaranteed that you'll always get the same workspace between the stages being executed.

I'm not got your point, what did you mean I can't get the same workspace? And if it do happen, how can it defeat my project build?

Could you please expalin it in detail?
Thanks in advance. :)
Bill.

@razzeee
Copy link

razzeee commented Aug 7, 2017

This script isn't using labels at all, it's directly adressing nodes. So that shouldn't be a problem.

Unfortunatly I'm currently searching for a solution how to build across multiple platforms with multiple nodes tagged by labels.

@BillHoo
Copy link
Author

BillHoo commented Aug 7, 2017

win32/android etc. are the lables indeed, and I've use it for years, maybe I should update the script I use for now cus' its already changed a lot.

@razzeee
Copy link

razzeee commented Aug 7, 2017

Hrm, well then that's just not listed in the official docs. https://jenkins.io/doc/book/pipeline/syntax/
And probably for a good reason, as I feel that it's a bit confusing and better when more expressively used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants