With Anthill Pro how can I programmatically kick off a new build? - anthill

I want to programatically kick off an Anthill job from another system and set some build properties (the Git branch).
What API exists to help me do that?

An alternative (simpler but less flexible) approach...
Create a Trigger on the build workflow and use wget or curl to send an HTTP POST to Anthill passing the required parameters with the POST.
Here is a way to send an HTTP POST using an HTML FORM.
http://anthillizer.com/display/main/How+to+create+a+simple+tool+to+fire+an+AnthillPro+CI+Trigger
You can do the same thing with wget.
Hope this helps!
Eric

You'll need to the Anthill SDK (click the 'tools' link at the top of the Anthill Pro screen)
Add the remoting/lib and remoting/conf to you classpath. Using these imports:
import com.urbancode.anthill3.domain.buildrequest.BuildRequest;
import com.urbancode.anthill3.domain.buildrequest.RequestSourceEnum;
import com.urbancode.anthill3.domain.project.Project;
import com.urbancode.anthill3.domain.project.ProjectFactory;
import com.urbancode.anthill3.domain.security.User;
import com.urbancode.anthill3.domain.security.UserFactory;
import com.urbancode.anthill3.domain.trigger.remoterequest.repository.RepositoryRequestTrigger;
import com.urbancode.anthill3.domain.workflow.Workflow;
import com.urbancode.anthill3.main.client.AnthillClient;
import com.urbancode.anthill3.persistence.UnitOfWork;
import com.urbancode.anthill3.runtime.scripting.helpers.WorkflowLookup;
import com.urbancode.anthill3.services.build.BuildService;
This code will look up a project and workflow then kick off a build.
AnthillClient anthill = AnthillClient.connect(hostStage, remotingPort, username, password);
UnitOfWork uow = anthill.createUnitOfWork();
Project prj = ProjectFactory.getInstance().restoreForName("My Project"); //'My Project' is the project name.
Workflow wflow = WorkflowLookup.getForProjectAndName(prj, "My Workflow"); //'My Workflow' is the workflows name/key
User usr = UserFactory.getInstance().restoreForName("username");
RepositoryRequestTrigger req1 = new RepositoryRequestTrigger();
req1.setWorkflow(wflow);
req1.setNew();
req1.setName("Git Repository Trigger");
uow.register(req1);
uow.commit();
BuildRequest br = BuildRequest.createOriginatingRequest(wflow.getBuildProfile(),usr, RequestSourceEnum.EVENT,req1);
br.setForcedFlag(true);
//Set any build properties here
br.setPropertyValue("gitBranch","develop",false);
BuildService.getInstance().runBuild(br);

Related

How to get the Project name with the new azure-devops-extension-sdk?

In the older SDK (vss-web-extension-sdk) - we could use VSS.getWebContext() to get the project name and id. I coudln't find a similar method in the newer SDK (azure-devops-extensions-sdk)
How can I get the project name with the new azure-devops-extensions-sdk?
There are samples azure-devops-extension-sample
Sample code:
import * as SDK from "azure-devops-extension-sdk";
import { CommonServiceIds, IProjectPageService } from "azure-devops-extension-api";
const projectService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
const project = await projectService.getProject();
https://github.com/microsoft/azure-devops-extension-sample/blob/master/src/Samples/Hub/OverviewTab.tsx
In the azure-devops-extension-sdk package I have not found an interface that can meet your need, but there is an IProjectInfo interface in the azure-devops-extension-api package could meet your demand.You could try it.
You could also try calling a REST API from your client-side extension to get project name. Here is the rest api as a reference:
curl -u {username}[:{personalaccesstoken}] https://dev.azure.com/{organization}/_apis/projects?api-version=2.0
For details,you can refer to this docs.

How to create dynamic folder selection parameter in Jankins pipeline

I am trying to use Jenkins as a tool as an automation build.
So, I need to create a pipline with parameter that helps me to select an appropriate directory where I start a build batch file.
By the moment, I have found how to select a directory as a parameter by usage of Extensible Choice plugin.
But it allows me to select a folder at one level, but I need to go deeper and get an oportunity to select via multilevel directory levels.
For example, select directory at level1 and than at level2 and finaly at level3.
Could you please give me any advise how to do that?
Use groovy script in pipeline job to dynamically assign the directory
Thanks. I have tried to find any similar example of code or plugin but haven't been succeed with this.
So, I have decided to do that based on a standard groovy syntax. Here is the code:
node {stage "Directories list output"
def dirname = getdirlist()
echo dirname}
import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
#NonCPS
def getdirlist() {def initialPath = System.getProperty("user.dir");
JFileChooser fc = new JFileChooser(initialPath);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fc.showOpenDialog( null );
switch ( result ){case JFileChooser.APPROVE_OPTION:
File file = fc.getSelectedFile();
def path = fc.getCurrentDirectory().getAbsolutePath();
def outputpath="path="+path+"\nfile name="+file.toString();
break;
case JFileChooser.CANCEL_OPTION:
case JFileChooser.ERROR_OPTION:
break;}
return outputpath}
I can't make it work. I have some suspitions that Jenkins pipeline doesn't allow to open a standard Java file dialog. What can be another aproach to my task?

importing dart code from other projects

** This question is edited and cleaned up some **
I have two projects and I want to use code from one in the other; I seem to be having trouble putting the code in the right directory structure to make the import statements work.
Both projects are created and managed exclusively from the Dart Editor on a Mac, if that makes any differences.
Project Directory Structures
Project 1: a command line app which contains the code I want to share in the following directory structure:
/dart/command_line_app
/lib
shared_library.dart
/bin
command_line_app.dart
Project 2: a web app which wants to import the code in shared_libary.dart
/dart/web_application
/packages
/web
web_application.dart
In the file shared_libary.dart, I declare it to be a library can create a simple class that provides output when instantiated:
library shared_library;
class ShareMe
{
ShareMe()
{
print("Hello, ShareMe");
}
}
This compiles, and works inside the command_line project: command_line_app.dart has the following:
import 'package:command_line_app/shared_library.dart';
void main() {
ShareMe shareMe = new ShareMe();
print("Hello, World!");
}
This imports the code runs, printing both "Hello Share Me," and Hello World.
THE PROBLEM
I want to instantiate the ShareMe class inside web_application.dart. I'd thought I could do that by putting in the same import statement I put in my command_line code:
import 'package:command_line_app/shared_library.dart';
But, when I put the same import into the web_appliation, it gets the error
Target of URI does not exist 'package:command_line_app/shared_library.dart'
Other Things I've Tried
I was certain I'd solved the problem when I cntrl-Clicked properties on Web_application and selected Project References.
It brings up a window allowing me to select command_line_app with a check box, but when I do, I get an error:
Could not set the project description for 'web_application' because the project description file (.project) is out of sync with the file system.
Whatever that means.
When I cntrl-click the underlined error and try Quick Fix it offers me "resolve dependencies" which sounds promising, but after a few seconds, it comes back and informs me that
Pub get failed, [1] Resolving dependencies... (15.3s)
Could not find package command_line_app at https://pub.dartlang.org.
Depended on by:
- web_application 0.0.0
I hope this is clear-er and gives a better insight into both what I'm trying to do and what I'm missing.
EDIT
you need to add
dependencies:
command_line_app:
path: ../command_line_app
to your dependencies in web_application/pubspec.yaml.
EDIT END
When you want to make code reusable in different packages, you should put that code into the lib directory of that package and import it using import 'package:mypackage/myfile.dart';.
Another problem you may face is, that browser applications can't import packages that have a dart:io dependency. If you want to reuse code between command line and browser applications you should move them into the lib directory of another package my_shared_code where you put only code that doesn't depend on dart:io (for example some entity classes) and import this code from both app packages (browser and command line).

How to change a Git URL in all Jenkins jobs

I have more than 100 jobs in Jenkins and I have to change a Git URL in each and every job since we changed the git server.
I must traverse each job and change the Git URL. Can anyone help me with a groovy script?
I was able to traverse each job, but not able to get the Git URL or change it:
import hudson.plugins.emailext.*
import hudson.model.*
import hudson.maven.*
import hudson.maven.reporters.*
import hudson.tasks.*
// For each project
for(item in Hudson.instance.items) {
println("JOB : " + item.name);
}
I badly need help in this, please someone help me.
The script below will modify all Git URL. You will need to fill the modifyGitUrl method. Script is written for Git plugin version 2.3.2. Check the git plugin source code to adjust it to the version you need e.g. the constructor parameters might have changed.
import hudson.plugins.git.*
import jenkins.*
import jenkins.model.*
def modifyGitUrl(url) {
// Your script here
return url + "modified"
}
Jenkins.instance.items.each {
if (it.scm instanceof GitSCM) {
def oldScm = it.scm
def newUserRemoteConfigs = oldScm.userRemoteConfigs.collect {
new UserRemoteConfig(modifyGitUrl(it.url), it.name, it.refspec, it.credentialsId)
}
def newScm = new GitSCM(newUserRemoteConfigs, oldScm.branches, oldScm.doGenerateSubmoduleConfigurations,
oldScm.submoduleCfg, oldScm.browser, oldScm.gitTool, oldScm.extensions)
it.scm = newScm
it.save()
}
}
I would have shut the server down and edited all the config.xml files with a script(sed/awk perl or something) and then restarted jenkins to load the new configurations.
If shutting down jenkins is not an option it is posible to get edit and post every config.xml with something like this
GET http://myserver/job/config.xml| sed s/oldurl/newurl/g |POST http://myserver/job/config.xml

Could not find class 'weka.core.FastVector',

I am using weka for my project. but get the error info"could not find class weka.core.FastVector" on the line below. I have already added weka.jar from the build path of the project by adding external jar file. How should I solve this problem? Thanks a lot for your time on reviewing my question.
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;
FastVector atts;
private void setUpARFF(){
atts = new FastVector();}
I know that FastVector was marked as obsolete a while back, perhaps they've finally removed it. Are you using the dev version of weka (or what version are you using)? FastVector can be replaced with ArrayList (in dev version) so use that instead.

Resources