Creating a Plugin

Hello,

just tried to write my own plugin. I want it to trigger a pipeline for a certain project each time a Tag is created on any project.

I followed the instructions here:
https://docs.gitlab.com/ee/administration/plugins.html

My questions:

  1. My plugin is triggered twice (2 pipelines are created) when i create a tag in my repository and 3 times when i delete a tag. Any idea/hint why this is the case?
  2. Is there a way to use gitlab internal functions instead of the api ?
  3. Is there a way to add configuration options to the GUI from within the plugin?

This is my plugin - as workaround its writing a temporary file and compares before and after hash to avoid multiple pipeline execution:

#!/usr/bin/env ruby

require 'json'
require 'tmpdir'

payload = JSON.parse(STDIN.read)

# Only run this code in case we are dealing with tag_push event
if payload['event_name'] == 'tag_push'

	temp = Dir.tmpdir()
	shaFile = "#{temp}/gitlab-trigger.sha"

	# Get hash values to compare
	payloadHash = "#{payload['before']} #{payload['after']}"
	payloadHashBefore = File.read(shaFile) if File.exist?(shaFile)

	# Save before and after hash to compare
	File.delete(shaFile) if File.exist?(shaFile)
	File.write(shaFile, "#{payload['before']} #{payload['after']}")

	# Trigger Pipeline
 	if payloadHashBefore != payloadHash
 		exec('curl --request POST --form "token=TRIGGER_TOKEN" --form ref=master https://gitlab.example.org/api/v4/projects/36/trigger/pipeline')
	end
			
end

Thanks for your help.

Cheers,
Ochorocho

Hi @ochorocho if you find any information regarding plugin creation for Gitlab could you please provide some data? I need to create plugin too but I don’t know how to do that for Gitlab (

Plugin system is kinda event based script
https://docs.gitlab.com/ee/administration/plugins.html

If you need in depth Integration in gitlab you need to go with the Partner Integration. Therefore you need to ask a gitlab Team member for details