Class StashNotifier

All Implemented Interfaces:
ExtensionPoint, Describable<Publisher>, BuildStep, SimpleBuildStep

public class StashNotifier extends Notifier implements SimpleBuildStep
Notifies a configured Atlassian Bitbucket server instance of build results through the Bitbucket build API.

Only basic authentication is supported at the moment.

  • Field Details

  • Constructor Details

    • StashNotifier

      @DataBoundConstructor public StashNotifier()
  • Method Details

    • getRequiredMonitorService

      public BuildStepMonitor getRequiredMonitorService()
      Specified by:
      getRequiredMonitorService in interface BuildStep
    • getStashServerBaseUrl

      public String getStashServerBaseUrl()
    • setStashServerBaseUrl

      @DataBoundSetter public void setStashServerBaseUrl(String stashServerBaseUrl)
    • getCredentialsId

      public String getCredentialsId()
    • setCredentialsId

      @DataBoundSetter public void setCredentialsId(String credentialsId)
    • isIgnoreUnverifiedSSLPeer

      public boolean isIgnoreUnverifiedSSLPeer()
    • setIgnoreUnverifiedSSLPeer

      @DataBoundSetter public void setIgnoreUnverifiedSSLPeer(boolean ignoreUnverifiedSSLPeer)
    • getCommitSha1

      public String getCommitSha1()
    • setCommitSha1

      @DataBoundSetter public void setCommitSha1(String commitSha1)
    • getBuildStatus

      public StashBuildState getBuildStatus()
    • setBuildStatus

      @DataBoundSetter public void setBuildStatus(Object buildStatus)
    • getBuildName

      public String getBuildName()
    • setBuildName

      @DataBoundSetter public void setBuildName(String buildName)
    • getBuildUrl

      public String getBuildUrl()
    • setBuildUrl

      @DataBoundSetter public void setBuildUrl(String buildUrl)
    • isIncludeBuildNumberInKey

      public boolean isIncludeBuildNumberInKey()
    • setIncludeBuildNumberInKey

      @DataBoundSetter public void setIncludeBuildNumberInKey(boolean includeBuildNumberInKey)
    • getProjectKey

      public String getProjectKey()
    • setProjectKey

      @DataBoundSetter public void setProjectKey(String projectKey)
    • isPrependParentProjectKey

      public boolean isPrependParentProjectKey()
    • setPrependParentProjectKey

      @DataBoundSetter public void setPrependParentProjectKey(boolean prependParentProjectKey)
    • isDisableInprogressNotification

      public boolean isDisableInprogressNotification()
    • setDisableInprogressNotification

      @DataBoundSetter public void setDisableInprogressNotification(boolean disableInprogressNotification)
    • isConsiderUnstableAsSuccess

      public boolean isConsiderUnstableAsSuccess()
    • setConsiderUnstableAsSuccess

      @DataBoundSetter public void setConsiderUnstableAsSuccess(boolean considerUnstableAsSuccess)
    • prebuild

      public boolean prebuild(AbstractBuild<?,?> build, BuildListener listener)
      Specified by:
      prebuild in interface BuildStep
      Overrides:
      prebuild in class BuildStepCompatibilityLayer
    • perform

      public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)
      Specified by:
      perform in interface BuildStep
      Overrides:
      perform in class BuildStepCompatibilityLayer
    • perform

      public void perform(@NonNull Run<?,?> run, @NonNull FilePath workspace, @NonNull Launcher launcher, @NonNull TaskListener listener)
      Specified by:
      perform in interface SimpleBuildStep
    • lookupCommitSha1s

      protected Collection<String> lookupCommitSha1s(Run run, FilePath workspace, TaskListener listener)
    • getHttpClient

      @Deprecated protected org.apache.http.impl.client.CloseableHttpClient getHttpClient(PrintStream logger, Run<?,?> run, String stashServer) throws Exception
      Deprecated.
      Returns the HttpClient through which the REST call is made. Uses an unsafe TrustStrategy in case the user specified a HTTPS URL and set the ignoreUnverifiedSSLPeer flag.
      Throws:
      Exception
      See Also:
      • DefaultApacheHttpNotifier.getHttpClient(PrintStream, URI, boolean)
    • getDescriptor

      public StashNotifier.DescriptorImpl getDescriptor()
      Specified by:
      getDescriptor in interface Describable<Publisher>
      Overrides:
      getDescriptor in class Notifier
    • notifyStash

      protected NotificationResult notifyStash(PrintStream logger, Run<?,?> run, String commitSha1, TaskListener listener, StashBuildState state)
      Notifies the configured Bitbucket server by POSTing the run results to the Bitbucket run API.
      Parameters:
      logger - the logger to use
      run - the run to notify Bitbucket of
      commitSha1 - the SHA1 of the run commit
      listener - the run listener for logging
      state - the state of the build as defined by the Bitbucket API.
    • getPushedBuildStatus

      protected StashBuildState getPushedBuildStatus(StashBuildState currentBuildStatus)
      Returns the build state to be pushed. This will select the specifically overwritten build state or the current build state else.
      Parameters:
      currentBuildStatus - the state of the current build
      Returns:
      the current build status
    • createRequest

      protected org.apache.http.client.methods.HttpPost createRequest(org.apache.http.HttpEntity stashBuildNotificationEntity, Item project, String commitSha1, String url) throws org.apache.http.auth.AuthenticationException
      Deprecated.
      in favor of method overload
      Returns the HTTP POST request ready to be sent to the Bitbucket build API for the given run and change set.
      Parameters:
      stashBuildNotificationEntity - a entity containing the parameters for Bitbucket
      commitSha1 - the SHA1 of the commit that was built
      url - Bitbucket URL
      Returns:
      the HTTP POST request to the Bitbucket build API
      Throws:
      org.apache.http.auth.AuthenticationException
      See Also:
      • DefaultApacheHttpNotifier.createRequest(URI, JSONObject, Credentials, NotificationContext)
    • getBuildKey

      protected String getBuildKey(Run<?,?> run, TaskListener listener)
      Returns the run key used in the Bitbucket notification. Includes the run number depending on the user setting.
      Parameters:
      run - the run to notify Bitbucket of
      Returns:
      the run key for the Bitbucket notification
    • getBuildName

      protected String getBuildName(Run<?,?> run)
      Returns the build name to be pushed. This will select the specifically overwritten build name or get the build name from the Run.
      Parameters:
      run - the run to notify Bitbucket of
      Returns:
      the name of the run
    • getBuildUrl

      protected String getBuildUrl(Run<?,?> run)
      Returns the build url to be pushed. This will select the specifically overwritten build url or get the build url from the DisplayURLProvider.
      Parameters:
      run - the run to notify Bitbucket of
      Returns:
      the url of the run
    • getBuildDescription

      protected String getBuildDescription(Run<?,?> run, StashBuildState state)
      Returns the description of the run used for the Bitbucket notification. Uses the run description provided by the Jenkins job, if available.
      Parameters:
      run - the run to be described
      state - the state of the run
      Returns:
      the description of the run