Adding a Teamcity schedule build trigger with Kotlin - kotlin

I am trying to add a schedule trigger for my Teamcity build and the project settings format switched to Kotlin. I added to my settings.kts
import jetbrains.buildServer.configs.kotlin.triggers.schedule
import jetbrains.buildServer.configs.kotlin.triggers
project {
triggers {
schedule {
schedulingPolicy = daily {
hour = 5
minute = 30
}
triggerBuild = always()
withPendingChangesOnly = false
}
}
}
But the trigger does not appear in Teamcity. What is the reason and what am I doing wrong?

Triggers are part of builds not projects. You should do it like this:
project {
buildType {
triggers {
schedule {
schedulingPolicy = daily {
hour = 1
}
triggerBuild = always()
enableQueueOptimization = false
}
}
}
}

Related

Issue using Mobbeel Fataar plugin with uploadArchives task

I'm in the process of trying to create a fat AAR to distribute my Android library. I'm using the Mobbeel Fataar plugin to package all of my dependencies into an AAR for ease of distribution. This works perfectly, and when I run ./gradlew build, I get an AAR file in mylibrary/build/outputs/aar/ called mylibrary-release.aar and it includes all of my dependencies in its libs directory. The issue arises when I attempt to distribute the AAR.
In order to distribute, I found this tutorial to take me through it, which I'm using virtually unchanged. Here's that code (in my build.gradle):
apply plugin: 'maven'
apply plugin: 'signing'
def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}
def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}
def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
}
}
The issue is that, when I run ./gradlew :mylibrary:uploadArchives, it creates a mylibrary-1.0.aar file in mylibrary/build/outputs/aar/ and uploads that file. The problem is that it doesn't have my dependencies bundled in.
I'd like to somehow create mylibrary-1.0.aar with all of my dependencies bundled, and then have that be uploaded. Unfortunately I don't have a completely clear understanding of how the upload code I'm using works. Does anyone know how I can do what I want?

Configuration for multi-step parallel stages

I have a mono-repo that contains multiple services. Ideally, I want to test each service in parallel. Each branch has 2 stages:
test
benchmark
To give something similar to this:
clone
/ \
/ \
/ \
/ \
svc1-test svc2-test
| |
svc1-bench svc2-bench
\ /
\ /
\ /
\ /
notify
The build would pass only if the all branches have succeeded. Furthermore, we could fail a branch early and not execute the benchmarking if the tests fail for any given branch.
From reading the documentation I see how I can run parallel stages using group, but not how to put many stages in a single branch.
I guess my fallback solution would be to put combine test+benchmark in a single stage, but I think it would be nice to isolate them, especially since the dependencies may vary for each.
I was looking for something similar and found it answered here by the user cdieck.
This is how it looks in Blue Ocean.
Copying the same for quick reference:
pipeline {
agent none
stages {
stage("Example") {
failFast true
parallel {
stage("win7-vs2012") {
agent {
label "win7-vs2012"
}
stages {
stage("checkout (win7-vs2012)") {
steps {
echo "win7-vs2012 checkout"
}
}
stage("build (win7-vs2012)") {
steps {
echo "win7-vs2012 build"
}
}
stage("test (win7-vs2012)") {
steps {
build 'test-win7-vs2012'
}
}
}
}
stage("win10-vs2015") {
agent {
label "win10-vs2015"
}
stages {
stage("checkout (win10-vs2015)") {
steps {
echo "win10-vs2015 checkout"
}
}
stage("build (win10-vs2015)") {
steps {
echo "win10-vs2015 build"
}
}
stage("test (win10-vs2015)") {
steps {
build 'test-win10-vs2015'
}
}
}
}
stage("linux-gcc5") {
agent {
label "linux-gcc5"
}
stages {
stage("checkout (linux-gcc5)") {
steps {
echo "linux-gcc5 checkout"
}
}
stage("build (linux-gcc5)") {
steps {
echo "linux-gcc5 build"
}
}
stage("test (linux-gcc5)") {
steps {
build 'test-linux-gcc5'
}
}
}
}
}
}
}
}

Custom Gradle task to build all projects without testing?

I know I can execute 'gradle build -x test', but is there a way to create a custom Gradle task, say, buildNoTests, which will build all of my projects but will completely ignore tests (don't compile/run them)?
I read that the 'assemble' task is not enough as it may miss other tasks which are not tests but are included in the 'build' task.
Put this in the root build.gradle
allprojects {
afterEvaluate {
def buildTask = tasks.findByPath('build')
if (buildTask) {
task buildNoTests {
dependsOn buildTask
}
gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
if (graph.hasTask(buildNoTests)) {
def skipNames = ['test', 'compileTestJava', 'processTestResources', 'testClasses'] as Set
Collection<Task> testTasks = graph.allTasks.findAll { skipNames.contains(it.name) }
testTasks.each { it.enabled = false }
}
}
}
}
}

Opening chrome should cause the extension to check the output of an API.How can this be possible?

Hi I am developing a website as my chrome extension.the extension periodically checks the output of a server file and then works according to the output of the server file.Now what I need is that presently it checks the output of the server file every 5 min.So what I need is that when the output of the server file changes at any time,at that moment I have to do some operations.How can I do this?
Here is my background.js
var myNotificationID = null;
var oldChromeVersion = !chrome.runtime;
chrome.windows.onCreated.addListener(function (){
updateIcon();
});
chrome.tabs.onCreated.addListener(function (){
updateIcon();
});
chrome.tabs.onUpdated.addListener(function (){
updateIcon();
});
function getGmailUrl() {
return "http://calpinemate.com/";
}
function isGmailUrl(url) {
return url.indexOf(getGmailUrl()) == 0;
}
chrome.windows.onCreated.addListener(function (){
updateIcon();
});
function onInit() {
updateIcon();
if (!oldChromeVersion) {
chrome.alarms.create('watchdog',{periodInMinutes:5,delayInMinutes: 0});
}
}
function onAlarm(alarm) {
if (alarm && alarm.name == 'watchdog') {
onWatchdog();
}
else {
updateIcon();
}
}
function onWatchdog() {
chrome.alarms.get('refresh', function(alarm) {
if (alarm) {
console.log('Refresh alarm exists. Yay.');
}
else {
updateIcon();
}
});
}
if (oldChromeVersion) {
updateIcon();
onInit();
}
else {
chrome.runtime.onInstalled.addListener(onInit);
chrome.alarms.onAlarm.addListener(onAlarm);
}
It is the updateIcon() which reads the server file.And when there is change in the output of server file,I have to call the updateIcon() itself.Presently only in every 5 min,the output is checked and updated in extension.But I need it to happen at the moment the status of server file changes.Anyone please help me.
In short,what I need is that when the output of API changes at any time at that time I have to call updateIcon().
Here is my updateIcon()
function updateIcon(){
var urlPrefix = 'http://www.calpinemate.com/employees/attendanceStatus/';
var urlSuffix = '/2';
var req = new XMLHttpRequest();
req.addEventListener("readystatechange", function() {
if (req.readyState == 4) {
if (req.status == 200) {
var item=req.responseText;
if(item==1){
.....//something
}
else{
// do something
}
else {
alert("ERROR: status code " + req.status);
}
}
});
var url = urlPrefix + encodeURIComponent(localStorage.username) + urlSuffix;
req.open("GET", url);
req.send(null);
}
I need to periodically monitor the API for output.
You could use a WebSocket to maintain a persistent, two-way channel between the server and your extension.
But, considering that PHP does not have native support for WebSockets (i.e. you would need to use an external library) and the fact that the interaction will be infrequent (only at log-in/-out), it might be unnecessary overhead.
I suggest you communicate the login-status directly from your web-page to your extension. For a more detailed description of the process, see my answer to one similar question of yours.
UPDATE:
Since it turned out you don't have control of the domain you need to "monitor", there is unfortunately no other option (that I know of) than polling at frequent intervals on that server-resource.
If you are using a non-persistent background-page (which is advisable due to its resource-friendliness) you must use the chrome.alarms API, which allows at most 1 triggering per minute: (in order to reduce the load on the user's machine - note: to help debug your extension, this limit is no imposed on unpacked extensions).
If you decide to use a persistent background-page, you can use setInterval() with an arbitrarily smal period (in milliseconds):
setInterval(function() {
/* Check up on the server */
...
}, 30000); // <-- trigger every 30.000 milliseconds (== 30 seconds)

Executing SQL in a Gradle task?

How can I execute SQL in a Gradle task?
configurations {
compile
}
repositories {
mavenCentral()
}
dependencies {
compile 'postgresql:postgresql:9.0-801.jdbc4'
}
task sql << {
driverName = 'org.postgresql.Driver'
Class.forName(driverName)
groovy.sql.Sql sql = Sql.newInstance(
'jdbc:postgresql://localhost:5432/postgres',
'username',
'password',
driverName
)
sql.execute 'create table test (id int not null)'
sql.execute 'insert into test (id) values(1)'
sql.eachRow 'select * from test' {
println it
}
}
I get a
java.lang.ClassNotFoundException: org.postgresql.Driver exception when executing the sql task.
To define external dependencies for the build script itself you got to put it into the build scripts' classpath. You can do that by defining it within the buildscript closure.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'postgresql:postgresql:9.0-801.jdbc4'
}
}
If you don't mind depending on yet another tool, you can leverage dbdeploy in your project. There is also a gradle plugin that let you import SQL scripts as is.
buildscript {
dependencies {
classpath 'com.oracle:ojdbc6:11.2.0.3'
}
}
task tmp() {
dependsOn configurations.batch
doLast {
ant.sql(classpath: buildscript.configurations.classpath.asPath,
driver: "oracle.jdbc.OracleDriver",
url: "${dbConn}", userid: "${dbUser}", password: "${dbPass}",
"select 1 from dual")
}
}
Alternatively:
ant.sql(classpath: buildscript.configurations.classpath.asPath,
driver: "oracle.jdbc.OracleDriver",
url: "${dbConn}", userid: "${dbUser}", password: "${dbPass}") {
fileset(dir: dir) {
include(name: "**/*.sql")
}
}
Found runsql-gradle-plugin that allows executing SQL script files defined in custom Gradle task.
After adding these strings to my build.gradle.kts:
plugins {
id("com.nocwriter.runsql") version ("1.0.3")
}
task<RunSQL>("initData") {
dependencies {
implementation("org.postgresql:postgresql")
}
config {
url = "jdbc:postgresql://localhost:5432/test"
driverClassName = "org.postgresql.Driver"
username = "test"
password = "test"
scriptFile = "data.sql"
}
}
I could execute data.sql by:
./gradlew initData
Here is one way:
gradle.class.classLoader.addURL(new File('../../../../lib/server/mssql/sqljdbc4.jar').toURI().toURL())
def Sql sql = Sql.newInstance(dbConnectionURL, dbUserName, dbPassword, dbDriverName)
String sqlString = new File(dbSchemaFile as String).text
sql.execute(sqlString)