URL: https://github.com/SSSD/sssd/pull/894
Author: pbrezina
 Title: #894: [wip] ci: multiple improvements
Action: synchronized

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/894/head:pr894
git checkout pr894
From b1db544c89300966f9485cc09150823b2abe35c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com>
Date: Wed, 4 Sep 2019 14:50:43 +0200
Subject: [PATCH 1/3] ci: enable on demand runs

---
 Jenkinsfile | 79 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 71 insertions(+), 8 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 90a636da62..8a85f5aee4 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -40,6 +40,18 @@ class CI {
    */
   public static String CIDir = this.BaseDir + '/sssd-ci'
 
+  /**
+   * True if this was executed as on demand run.
+   *
+   * Github notifications are disabled in this mode.
+   */
+  public static boolean OnDemandRun = false
+
+  /**
+   * User that triggered this build.
+   */
+  public static String User = 'sssd-ci'
+
   /**
    * Workaround for https://issues.jenkins-ci.org/browse/JENKINS-39203
    *
@@ -81,10 +93,30 @@ class CI {
     return this.RebaseResults[build] == "success"
   }
 
+  /**
+   * Setup initial variables.
+   */
+  public static def Setup(ctx) {
+    if (ctx.params.ON_DEMAND) {
+      this.OnDemandRun = true
+
+      def build = ctx.currentBuild.rawBuild
+      def cause = build.getCause(hudson.model.Cause.UserIdCause.class)
+      this.User = cause.getUserId()
+      ctx.currentBuild.description = "${this.User}: ${ctx.params.REPO_BRANCH}"
+    } else {
+      this.OnDemandRun = false
+    }
+  }
+
   /**
    * Send commit status to Github for sssd-ci context.
    */
   public static def Notify(ctx, status, message) {
+    if (this.OnDemandRun) {
+      return
+    }
+
     ctx.githubNotify status: status,
       context: this.GHContext,
       description: message,
@@ -95,6 +127,10 @@ class CI {
    * Send commit status to Github for specific build (e.g. sssd-ci/fedora28).
    */
   public static def NotifyBuild(ctx, status, message) {
+    if (this.OnDemandRun) {
+      return
+    }
+
     ctx.githubNotify status: status,
       context: String.format('%s/%s', this.GHContext, ctx.env.TEST_SYSTEM),
       description: message,
@@ -107,8 +143,21 @@ class CI {
       )
   }
 
+  public static def Checkout(ctx) {
+    if (!this.OnDemandRun) {
+      /* The repository is checked out automatically. */
+      return
+    }
+
+    ctx.dir('sssd') {
+        ctx.git branch: "${ctx.params.REPO_BRANCH}", url: "${ctx.params.REPO_URL}"
+    }
+  }
+
   public static def Rebase(ctx) {
-    if (!ctx.env.CHANGE_TARGET) {
+    /* Do not rebase if there is no target available (not a pull request) or
+     * this is an on demand run. */
+    if (!ctx.env.CHANGE_TARGET || this.OnDemandRun) {
       this.RebaseSuccessful(ctx.env.TEST_SYSTEM)
       return
     }
@@ -147,8 +196,15 @@ class CI {
    * Run tests. TEST_SYSTEM environment variable must be defined.
    */
   public static def RunTests(ctx) {
+    if (this.OnDemandRun) {
+      ctx.echo "This build was requested by: ${this.User}"
+      ctx.echo "Repository: ${ctx.params.REPO_URL}"
+      ctx.echo "Branch: ${ctx.params.REPO_BRANCH}"
+    }
+
     ctx.echo "Running on ${ctx.env.NODE_NAME}"
     this.NotifyBuild(ctx, 'PENDING', 'Build is in progress.')
+    this.Checkout(ctx)
     this.Rebase(ctx)
 
     ctx.echo String.format(
@@ -183,13 +239,18 @@ class CI {
     }
 
     ctx.archiveArtifacts artifacts: "artifacts/**", allowEmptyArchive: true
-    ctx.sh String.format(
-      '%s/sssd-ci archive --name "%s" --system "%s" --artifacts "%s"',
-      "${this.CIDir}",
-      "${ctx.env.BRANCH_NAME}/${ctx.env.BUILD_ID}",
-      ctx.env.TEST_SYSTEM,
-      "${ctx.env.WORKSPACE}/artifacts/${ctx.env.TEST_SYSTEM}"
-    )
+
+    if (this.OnDemandRun) {
+      ctx.echo 'This is an on demand run. Artifacts are not stored in the cloud.'
+    } else {
+      ctx.sh String.format(
+        '%s/sssd-ci archive --name "%s" --system "%s" --artifacts "%s"',
+        "${this.CIDir}",
+        "${ctx.env.BRANCH_NAME}/${ctx.env.BUILD_ID}",
+        ctx.env.TEST_SYSTEM,
+        "${ctx.env.WORKSPACE}/artifacts/${ctx.env.TEST_SYSTEM}"
+      )
+    }
     ctx.sh "rm -fr ${ctx.env.WORKSPACE}/artifacts/${ctx.env.TEST_SYSTEM}"
 
     if (this.IsBuildSuccessful(ctx.env.TEST_SYSTEM)) {
@@ -213,6 +274,7 @@ class CI {
  * yield 'Expected a symbol' error for some reason. This is a workaround
  * for this issue.
  */
+def CI_Setup() { CI.Setup(this) }
 def CI_RunTests() { CI.RunTests(this) }
 def CI_Post() { CI.WhenCompleted(this) }
 def CI_Aborted() { CI.WhenAborted(this) }
@@ -226,6 +288,7 @@ pipeline {
   stages {
     stage('Prepare') {
       steps {
+        CI_Setup()
         CI_Notify('PENDING', 'Running tests.')
       }
     }

From 226b0badf206a4e2710a5f438e0dc2f2f46add28 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com>
Date: Thu, 26 Sep 2019 11:50:53 +0200
Subject: [PATCH 2/3] ci: set build name to pull request or branch name

This way it will be easier to orient in the build list.
---
 Jenkinsfile | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/Jenkinsfile b/Jenkinsfile
index 8a85f5aee4..52578280d8 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -106,6 +106,17 @@ class CI {
       ctx.currentBuild.description = "${this.User}: ${ctx.params.REPO_BRANCH}"
     } else {
       this.OnDemandRun = false
+      
+      /* Set a nice name */
+      if (ctx.env.CHANGE_TARGET) {
+        def title = ctx.sh returnStdout: true, script: """
+          curl -s https://api.github.com/repos/SSSD/sssd/pulls/${ctx.env.CHANGE_ID} | \
+          python -c "import sys, json; print(json.load(sys.stdin).get('title'))"
+        """
+        ctx.currentBuild.description = "PR ${ctx.env.CHANGE_ID}: ${title}"
+      } else {
+        ctx.currentBuild.description = "Branch: ${ctx.env.BRANCH_NAME}"
+      }
     }
   }
 
@@ -287,6 +298,9 @@ pipeline {
   }
   stages {
     stage('Prepare') {
+      agent {
+        label 'master'
+      }
       steps {
         CI_Setup()
         CI_Notify('PENDING', 'Running tests.')

From 75b7bf8f104bd4d8ef4c27f883e60bb266d84a1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com>
Date: Thu, 26 Sep 2019 12:36:14 +0200
Subject: [PATCH 3/3] ci: notify that build awaits executor

This way, the old status will be removed with message 'awaiting executors'
instead of showing old success/failure state.
---
 Jenkinsfile | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 52578280d8..547bf645e6 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -137,13 +137,13 @@ class CI {
   /**
    * Send commit status to Github for specific build (e.g. sssd-ci/fedora28).
    */
-  public static def NotifyBuild(ctx, status, message) {
+  public static def NotifyBuild(ctx, build, status, message) {
     if (this.OnDemandRun) {
       return
     }
 
     ctx.githubNotify status: status,
-      context: String.format('%s/%s', this.GHContext, ctx.env.TEST_SYSTEM),
+      context: String.format('%s/%s', this.GHContext, build),
       description: message,
       targetUrl: String.format(
         '%s/%s/%s/%s/index.html',
@@ -214,7 +214,7 @@ class CI {
     }
 
     ctx.echo "Running on ${ctx.env.NODE_NAME}"
-    this.NotifyBuild(ctx, 'PENDING', 'Build is in progress.')
+    this.NotifyBuild(ctx, ctx.env.TEST_SYSTEM, 'PENDING', 'Build is in progress.')
     this.Checkout(ctx)
     this.Rebase(ctx)
 
@@ -245,7 +245,7 @@ class CI {
   public static def WhenCompleted(ctx) {
     if (!this.IsRebaseSuccessful(ctx.env.TEST_SYSTEM)) {
       ctx.echo "Unable to rebase on target branch."
-      this.NotifyBuild(ctx, 'FAILURE', 'Unable to rebase on target branch.')
+      this.NotifyBuild(ctx, ctx.env.TEST_SYSTEM, 'FAILURE', 'Unable to rebase on target branch.')
       return
     }
 
@@ -265,18 +265,18 @@ class CI {
     ctx.sh "rm -fr ${ctx.env.WORKSPACE}/artifacts/${ctx.env.TEST_SYSTEM}"
 
     if (this.IsBuildSuccessful(ctx.env.TEST_SYSTEM)) {
-      this.NotifyBuild(ctx, 'SUCCESS', 'Success.')
+      this.NotifyBuild(ctx, ctx.env.TEST_SYSTEM, 'SUCCESS', 'Success.')
       return
     }
 
-    this.NotifyBuild(ctx, 'FAILURE', 'Build failed.')
+    this.NotifyBuild(ctx, ctx.env.TEST_SYSTEM, 'FAILURE', 'Build failed.')
   }
 
   /**
    * Notify Github that the build was aborted.
    */
   public static def WhenAborted(ctx) {
-    this.NotifyBuild(ctx, 'ERROR', 'Aborted.')
+    this.NotifyBuild(ctx, ctx.env.TEST_SYSTEM, 'ERROR', 'Aborted.')
   }
 }
 
@@ -290,6 +290,7 @@ def CI_RunTests() { CI.RunTests(this) }
 def CI_Post() { CI.WhenCompleted(this) }
 def CI_Aborted() { CI.WhenAborted(this) }
 def CI_Notify(status, message) { CI.Notify(this, status, message) }
+def CI_NotifyBuild(build, status, message) { CI.NotifyBuild(this, build, status, message) }
 
 pipeline {
   agent none
@@ -304,6 +305,11 @@ pipeline {
       steps {
         CI_Setup()
         CI_Notify('PENDING', 'Running tests.')
+        CI_NotifyBuild('fedora28', 'PENDING', 'Awaiting executors.')
+        CI_NotifyBuild('fedora29', 'PENDING', 'Awaiting executors.')
+        CI_NotifyBuild('fedora30', 'PENDING', 'Awaiting executors.')
+        CI_NotifyBuild('fedora-rawhide', 'PENDING', 'Awaiting executors.')
+        CI_NotifyBuild('debian10', 'PENDING', 'Awaiting executors.')
       }
     }
     stage('Run Tests') {
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org

Reply via email to