'Gitlab multiproject pipeline points to the old commit when rerunning it
We've got a multi-project pipeline:
Project A:
...
stages:
- build
- test
build:
stage: build
some long building job setup
release testing:
stage: test
allow_failure: false
only:
- /^\d+\.\d+\.\d+$/
when: on_success
trigger:
project: projectB
branch: release
strategy: depend
...
Project B:
...
test:
stage: test
script:
- run_tests.sh
Whenever a new release is rolled out on project A we trigger a multi-project pipeline on project B to test it automatically. Once we see the fails in B (due to the changes in A) we want to update the tests in B and commit them to release branch. Then we want to retrigger 'release testing' pipeline multi-project pipeline to verify the test changes are correct.
But we have a problem here. Once the multi-project pipeline is triggered it ties to a specific commit in project B. And if you click rerun on the Downstream job of A it will still run against the same commit in B. Is there a way to pick the latest commit of the target branch once you rerun the job other than retriggering the whole project A pipeline?
Solution 1:[1]
I have done it in Kotlin. If you face problem in converting Kotlin into Java you can ask me for help.
So, I am using Broadcast Receiver and detect whenever the network state changed and when there is no Internet, a dialogBox will show.
MainActivity.kt
class MainActivity : AppCompatActivity() {
private var br: BroadcastReceiver? = null
private var filter: IntentFilter? = null
private var mContext: MainActivity? = null
private var isPaused = false
private var toConfirm = true
private var noInternetBuilder: AlertDialog.Builder? = null
private var noInternetDialog: AlertDialog? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
br = MyBroadCastReceiver()
filter = IntentFilter()
filter?.addAction("android.net.conn.CONNECTIVITY_CHANGE")
mContext = this@MainActivity
mContext?.registerReceiver(br, filter)
}
/**
* Broadcast for Internet Checking
*
*/
inner class MyBroadCastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (!isNetworkStatusAvailable(this@MainActivity)) {
if (!isPaused) {
toConfirm = true
if (noInternetDialog != null) {
noInternetDialog?.dismiss()
}
showDialogNoInternet(this@MainActivity)
}
toConfirm = false
} else {
toConfirm = true
if (noInternetDialog != null) {
if (noInternetDialog!!.isShowing) {
noInternetDialog?.dismiss()
}
}
}
}
}
fun isNetworkStatusAvailable(context: Context): Boolean {
var result = false
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val networkCapabilities = connectivityManager.activeNetwork ?: return false
val actNw =
connectivityManager.getNetworkCapabilities(networkCapabilities) ?: return false
result = when {
actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
else -> false
}
} else {
@Suppress("DEPRECATION")
connectivityManager.run {
connectivityManager.activeNetworkInfo?.run {
result = when (type) {
ConnectivityManager.TYPE_WIFI -> true
ConnectivityManager.TYPE_MOBILE -> true
ConnectivityManager.TYPE_ETHERNET -> true
else -> false
}
}
}
}
return result
}
fun showDialogNoInternet(activity: Activity) {
noInternetBuilder = AlertDialog.Builder(activity)
val viewGroup = findViewById<ViewGroup>(android.R.id.content)
val dialogView: View = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.dialog_nointernet, viewGroup, false)
noInternetBuilder!!.setView(dialogView)
noInternetDialog = noInternetBuilder!!.create()
noInternetDialog!!.setCancelable(false)
noInternetDialog!!.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val btn = dialogView.findViewById<View>(R.id.btnOkInternet) as Button
btn.setOnClickListener {
resultInternetLauncher.launch(Intent(Settings.ACTION_WIFI_SETTINGS))
noInternetDialog?.dismiss()
}
noInternetDialog!!.show()
}
override fun onPause() {
super.onPause()
isPaused = true
}
override fun onResume() {
super.onResume()
isPaused = false
if (!toConfirm) {
if (noInternetDialog != null) {
noInternetDialog?.dismiss()
}
showDialogNoInternet(mContext!!)
}
}
}
Must implement override fun onPause() and override fun onResume() along with it because it will control the crashes of dialogBox.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Talha Naeem |
