It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to render my freemarker template from java?

Hi,

please I am new to Bamboo development and have some question, if you could hellp me.

I have this xWork:

<xwork key="viewNFTResults" name="View NFT Results">
<package name="nftResults" extends="buildResultView">
<action name="viewNFTResults" class="com.atlassian.sap.nftresults.impl.MyPostJobAction">
<result name="success" type="freemarker">/fragments/view-nft-results-log.ftl</result>
</action>
</package>
</xwork>

<web-item key="NFT:\${planKey}-\${buildNumber}" name="chainNFTResults" section="chainResults.subMenu/chainResults"
weight="80">
<label key="NFT Results"/>
<link linkId="NFT:\${planKey}-\${buildNumber}">/browse/nft_results/viewNFTResults.action?buildKey=${planKey}&amp;buildNumber=${buildNumber}</link>
</web-item>

 

First Question: please any exapmles what I can use instead of  extends="buildResultView", which choises?

Second Question: any examples about the action element? how the result element works?

Third Question: in the MyPostJobAction I implement PostJobAction and I override the excute method, because I need to get some data after every job is finished, here I want to render the view-nft-results-log.ftl file with new context, I do like that:

public class MyPostJobAction extends PlanResultsAction implements PostJobAction {

public void execute(@NotNull StageExecution stageExecution, @NotNull Job job,
@NotNull BuildResultsSummary buildResultsSummary) {

// for example i have here a map that I will fill with my own data
Map<String, Object> objectMap = new HashMap<String, Object>();


objectMap.put("NFTResults", Job);

//from here please how I can provide my ftl file with this map as a new context
and how to render the ftl file also from here after that?
}
thank you very much in advance. 

 

1 answer

1 vote

1. Don't extend PostJobActions, it's not meant for UI at all. It's an action that executes as part of the build process. If you need such thing at all, it should be a separate class.

2. Your action class should be sth like

public class MyAction extends BuildResultsAction {

public String execute() {
BuildResultSummary bs = getBuildResultsSummary();
//do stuff with the result
return SUCCESS; //this is ftl result
}
}

You DON'T render ftl template. Framework does it for you. If you want to use data from the action in the template you expose it by declaring a public method in the action class for instance, if you want to have this in the ftl:

${myData}

 you do the following in the action:

public String getMyData() {
return "blah blah blah";
}

You can use other types than String of course. NFTResults

3. Action return element tells the framework what to do after your action depending on what your action returns. Your execute method returns a string. The string is the matched against defined return elements and matching action is executed. The action can be  for instance rendering an ftl template or redirecting to another action.

Hi Marcin,

Thank you, your answer solved one problem but I still have another one, if you can help me please.

I implemented PostJobAction here becasue I need to perform a functionaltily when the every job is finished and provide the result once agian to the ftl file to show it inside the tab.

That is why I asked about render ftl template from java code.

So, I need to render the ftl template UI after evrey job is finished.

 

Thank you very much in advance. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bamboo

Unable to add or edit Bitbucket Cloud repository in Bamboo

On 31 May, a GDPR-related change went live in the Bitbucket Cloud API that resulted in users not being able to create or edit Bitbucket Cloud Linked repositories in Bamboo. This API update removed t...

663 views 2 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you