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 nodes by label step #39

Merged
merged 4 commits into from
Feb 13, 2018
Merged

Add nodes by label step #39

merged 4 commits into from
Feb 13, 2018

Conversation

jetersen
Copy link
Member

@jetersen jetersen commented Feb 7, 2018

We have this step in our shared library.
The step enables us to maintain a group of nodes through Jenkins by using their label to get the desired group, ie. 'MacOS' label.
Currently, our shared library step is using the Jenkins JSON API, earlier it was using unsafe groovy methods.
So I suggest we add the step to this plugin 👍

The suggested name for the step is 'nodesByLabel' However I am open for better suggestion, also the package location.

Use case:

@Library('widex') _
def branches = [:]

def nodeNames = nodesByLabel 'macOS'
def XcodeVersion = '9.2'

nodeNames.each { nodeName ->
  branches[nodeName] = {
    node(nodeName) {
      stage("Install Xcode ${XcodeVersion} for ${nodeName}") {
        timeout(time:60, unit:'MINUTES') {
          withCredentials([
            usernamePassword(credentialsId: 'widex.appleid', passwordVariable: 'XCODE_INSTALL_PASSWORD', usernameVariable: 'XCODE_INSTALL_USER')
          ]) {
            sh "xcversion update"
            sh "xcversion install '${XcodeVersion}' --no-progress"
          }
        }
      }
    }
  }
}

parallel branches

}

@Override
protected ArrayList<String> run() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

You should not be that type specific here. List<String> is better.

@Override
@NonNull
public String getDisplayName() {
return "List of node names by their label";
Copy link
Member

Choose a reason for hiding this comment

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

I18n

If I grok the logic below this statement is not exactly true, since it only lists nodes that are online.
A potential enhancement could be to add an optional parameter allowing the caller to not filter out based on online state?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it filters on the online state. So the optional filter would be great 👍

@rsandell
Copy link
Member

#36 Is now merged, so you should target master instead.

@jetersen jetersen changed the base branch from newpom to master February 12, 2018 13:04
@jetersen
Copy link
Member Author

@rsandell rebased onto master and added your suggestion.

@rsandell rsandell merged commit 8c9fd13 into jenkinsci:master Feb 13, 2018
@rsandell
Copy link
Member

I forgot to ask you to update docs/STEPS.md. But there are others missing as well, so if you don't get to it before I start to prepare for release I can add it then.

@jetersen jetersen deleted the nodesByLabel-step branch February 27, 2020 06:46
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.

2 participants