package net.masterthought.jenkins;

import hudson.model.Job;
import hudson.model.ProminentProjectAction;
import hudson.model.Run;
import net.masterthought.cucumber.ReportBuilder;

public class CucumberReportProjectAction extends CucumberReportBaseAction implements ProminentProjectAction {

    private final Job<?, ?> project;

    public CucumberReportProjectAction(Job<?, ?> project) {
        this.project = project;
    }

    @Override
    public String getUrlName() {
        Run<?, ?> run = this.project.getLastCompletedBuild();
        if (run != null) {
            return extractBuildNumber(run.getUrl()) + "/" + ReportBuilder.BASE_DIRECTORY + "/" + ReportBuilder.HOME_PAGE;
        }

        // none build was completed, report is yet not available
        return "";
    }

    private String extractBuildNumber(String url) {
        // basic url format -> job/cucumber/125/
        // view url format  -> view/myview/job/cucumber/126/
        String buildNumber = url.substring(0, url.length() - 1);
        buildNumber = buildNumber.substring(buildNumber.lastIndexOf("/") + 1);
        return buildNumber;
    }
}
@@ -123,16 +123,17 @@
 el.Run;%0A
+%0A
 import n
@@ -581,39 +581,22 @@
 urn 
-extractBuildNumber(run.getUrl()
+run.getNumber(
 ) + 
@@ -767,347 +767,6 @@
    %7D
-%0A%0A    private String extractBuildNumber(String url) %7B%0A        // basic url format -%3E job/cucumber/125/%0A        // view url format  -%3E view/myview/job/cucumber/126/%0A        String buildNumber = url.substring(0, url.length() - 1);%0A        buildNumber = buildNumber.substring(buildNumber.lastIndexOf(%22/%22) + 1);%0A        return buildNumber;%0A    %7D
 %0A%7D

Build number does not have to be calculated (#225)